]> git.lizzy.rs Git - rust.git/commitdiff
Add doc example for `CString::into_boxed_c_str`.
authorCorey Farwell <coreyf@rwell.org>
Sun, 18 Jun 2017 22:45:00 +0000 (15:45 -0700)
committerCorey Farwell <coreyf@rwell.org>
Tue, 20 Jun 2017 17:49:27 +0000 (13:49 -0400)
src/libstd/ffi/c_str.rs

index 9b500a3d6263459cd7984cce88cfba3660e29a57..b84b4d6dd7d1bdbedca0ec79a4facec435b2e443 100644 (file)
@@ -421,6 +421,18 @@ pub fn as_c_str(&self) -> &CStr {
     /// Converts this `CString` into a boxed [`CStr`].
     ///
     /// [`CStr`]: struct.CStr.html
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(into_boxed_c_str)]
+    ///
+    /// use std::ffi::{CString, CStr};
+    ///
+    /// let c_string = CString::new(b"foo".to_vec()).unwrap();
+    /// let boxed = c_string.into_boxed_c_str();
+    /// assert_eq!(&*boxed, CStr::from_bytes_with_nul(b"foo\0").unwrap());
+    /// ```
     #[unstable(feature = "into_boxed_c_str", issue = "40380")]
     pub fn into_boxed_c_str(self) -> Box<CStr> {
         unsafe { mem::transmute(self.into_inner()) }