X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibstd%2Fffi%2Fc_str.rs;h=5dae1a09bf410f7330a3786c8270b32fbc1b90ff;hb=3c5a0fa45b5e2786b6e64e27f48cd129e7aefdbd;hp=77b90c0846bbe44f2349b7a674223d6f47ea59f9;hpb=68d9284a9b7570ec32178e544f6f8ca7ac0be0f9;p=rust.git diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 77b90c0846b..5dae1a09bf4 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -211,8 +211,20 @@ fn _new(bytes: Vec) -> Result { /// This method is equivalent to `new` except that no runtime assertion /// is made that `v` contains no 0 bytes, and it requires an actual /// byte vector, not anything that can be converted to one with Into. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let raw = b"foo".to_vec(); + /// unsafe { + /// let c_string = CString::from_vec_unchecked(raw); + /// } + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn from_vec_unchecked(mut v: Vec) -> CString { + v.reserve_exact(1); v.push(0); CString { inner: v.into_boxed_slice() } }