Skip to content

Commit 65793b3

Browse files
committed
Add doc example for Box<CStr>::into_c_string.
1 parent db97145 commit 65793b3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libstd/ffi/c_str.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,18 @@ impl CStr {
939939
///
940940
/// [`Box`]: ../boxed/struct.Box.html
941941
/// [`CString`]: struct.CString.html
942+
///
943+
/// # Examples
944+
///
945+
/// ```
946+
/// #![feature(into_boxed_c_str)]
947+
///
948+
/// use std::ffi::CString;
949+
///
950+
/// let c_string = CString::new(b"foo".to_vec()).unwrap();
951+
/// let boxed = c_string.into_boxed_c_str();
952+
/// assert_eq!(boxed.into_c_string(), CString::new("foo").unwrap());
953+
/// ```
942954
#[unstable(feature = "into_boxed_c_str", issue = "40380")]
943955
pub fn into_c_string(self: Box<CStr>) -> CString {
944956
unsafe { mem::transmute(self) }

0 commit comments

Comments
 (0)