Skip to content

Commit 5efe083

Browse files
committed
Add Default implementation for &CStr and CString
1 parent 525aa61 commit 5efe083

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: 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)