Skip to content

Commit

Permalink
Auto merge of rust-lang#32990 - tbu-:pr_more_defaults_cstr_path, r=al…
Browse files Browse the repository at this point in the history
…excrichton

Add `Default` implementation for `&CStr`, `CString`, `Path`
  • Loading branch information
bors committed May 5, 2016
2 parents 413bafd + 5efe083 commit 77987ba
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,22 @@ impl fmt::Debug for CStr {
}
}

#[stable(feature = "cstr_default", since = "1.10.0")]
impl<'a> Default for &'a CStr {
fn default() -> &'a CStr {
static SLICE: &'static [c_char] = &[0];
unsafe { CStr::from_ptr(SLICE.as_ptr()) }
}
}

#[stable(feature = "cstr_default", since = "1.10.0")]
impl Default for CString {
fn default() -> CString {
let a: &CStr = Default::default();
a.to_owned()
}
}

#[stable(feature = "cstr_borrow", since = "1.3.0")]
impl Borrow<CStr> for CString {
fn borrow(&self) -> &CStr { self }
Expand Down

0 comments on commit 77987ba

Please sign in to comment.