summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-05-05 13:18:57 -0700
committerbors <bors@rust-lang.org>2016-05-05 13:18:57 -0700
commit77987ba89894997c174ac8b01185c0dc12913fa5 (patch)
tree9c16bdabff02b3e9cbda88205afbf4435a51b5ff /src/libstd
parent413bafdabf5c5716fd823ac9a6232c48e2ba2902 (diff)
parent5efe083ddca3bfa09e583ae7396f8af8c52b43eb (diff)
downloadrust-77987ba89894997c174ac8b01185c0dc12913fa5.tar.gz
rust-77987ba89894997c174ac8b01185c0dc12913fa5.zip
Auto merge of #32990 - tbu-:pr_more_defaults_cstr_path, r=alexcrichton
Add `Default` implementation for `&CStr`, `CString`, `Path`
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/ffi/c_str.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index 52d7bb128d5..fbc8886ce8f 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -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 }