mirror of
https://github.com/rust-lang/rust
synced 2024-09-15 22:50:55 +00:00
Add doc example for CString::into_boxed_c_str
.
This commit is contained in:
parent
82ba871c70
commit
db97145150
|
@ -421,6 +421,18 @@ pub fn as_c_str(&self) -> &CStr {
|
||||||
/// Converts this `CString` into a boxed [`CStr`].
|
/// Converts this `CString` into a boxed [`CStr`].
|
||||||
///
|
///
|
||||||
/// [`CStr`]: struct.CStr.html
|
/// [`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")]
|
#[unstable(feature = "into_boxed_c_str", issue = "40380")]
|
||||||
pub fn into_boxed_c_str(self) -> Box<CStr> {
|
pub fn into_boxed_c_str(self) -> Box<CStr> {
|
||||||
unsafe { mem::transmute(self.into_inner()) }
|
unsafe { mem::transmute(self.into_inner()) }
|
||||||
|
|
Loading…
Reference in a new issue