]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/ffi/c_str.rs
Auto merge of #35871 - bluss:cstring-new, r=alexcrichton
[rust.git] / src / libstd / ffi / c_str.rs
index 6f217be31fe678e513fbf5a3ac95a9b5d1b1cd1a..5dae1a09bf410f7330a3786c8270b32fbc1b90ff 100644 (file)
@@ -211,6 +211,17 @@ fn _new(bytes: Vec<u8>) -> Result<CString, NulError> {
     /// 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<u8>) -> CString {
         v.reserve_exact(1);