Skip to content

Commit db97145

Browse files
committed
Add doc example for CString::into_boxed_c_str.
1 parent 82ba871 commit db97145

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
@@ -421,6 +421,18 @@ impl CString {
421421
/// Converts this `CString` into a boxed [`CStr`].
422422
///
423423
/// [`CStr`]: struct.CStr.html
424+
///
425+
/// # Examples
426+
///
427+
/// ```
428+
/// #![feature(into_boxed_c_str)]
429+
///
430+
/// use std::ffi::{CString, CStr};
431+
///
432+
/// let c_string = CString::new(b"foo".to_vec()).unwrap();
433+
/// let boxed = c_string.into_boxed_c_str();
434+
/// assert_eq!(&*boxed, CStr::from_bytes_with_nul(b"foo\0").unwrap());
435+
/// ```
424436
#[unstable(feature = "into_boxed_c_str", issue = "40380")]
425437
pub fn into_boxed_c_str(self) -> Box<CStr> {
426438
unsafe { mem::transmute(self.into_inner()) }

0 commit comments

Comments
 (0)