We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
CString::into_boxed_c_str
1 parent 82ba871 commit db97145Copy full SHA for db97145
src/libstd/ffi/c_str.rs
@@ -421,6 +421,18 @@ impl CString {
421
/// Converts this `CString` into a boxed [`CStr`].
422
///
423
/// [`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
436
#[unstable(feature = "into_boxed_c_str", issue = "40380")]
437
pub fn into_boxed_c_str(self) -> Box<CStr> {
438
unsafe { mem::transmute(self.into_inner()) }
0 commit comments