Skip to content

Commit 77987ba

Browse files
committed
Auto merge of #32990 - tbu-:pr_more_defaults_cstr_path, r=alexcrichton
Add `Default` implementation for `&CStr`, `CString`, `Path`
2 parents 413bafd + 5efe083 commit 77987ba

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libstd/ffi/c_str.rs

+16
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,22 @@ impl fmt::Debug for CStr {
326326
}
327327
}
328328

329+
#[stable(feature = "cstr_default", since = "1.10.0")]
330+
impl<'a> Default for &'a CStr {
331+
fn default() -> &'a CStr {
332+
static SLICE: &'static [c_char] = &[0];
333+
unsafe { CStr::from_ptr(SLICE.as_ptr()) }
334+
}
335+
}
336+
337+
#[stable(feature = "cstr_default", since = "1.10.0")]
338+
impl Default for CString {
339+
fn default() -> CString {
340+
let a: &CStr = Default::default();
341+
a.to_owned()
342+
}
343+
}
344+
329345
#[stable(feature = "cstr_borrow", since = "1.3.0")]
330346
impl Borrow<CStr> for CString {
331347
fn borrow(&self) -> &CStr { self }

0 commit comments

Comments
 (0)