From db971451506763b860575786e5c391b6a1b149c5 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 18 Jun 2017 15:45:00 -0700 Subject: [PATCH] Add doc example for `CString::into_boxed_c_str`. --- src/libstd/ffi/c_str.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 9b500a3d626..b84b4d6dd7d 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -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 { unsafe { mem::transmute(self.into_inner()) }