Skip to content

Commit

Permalink
Add doc example for CString::into_boxed_c_str.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Jun 20, 2017
1 parent 82ba871 commit db97145
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/libstd/ffi/c_str.rs
Expand Up @@ -421,6 +421,18 @@ impl CString {
/// 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()) }
Expand Down

0 comments on commit db97145

Please sign in to comment.