mirror of
https://github.com/rust-lang/rust
synced 2024-09-05 08:37:14 +00:00
Add doc example for CString::as_c_str
.
This commit is contained in:
parent
65793b30d3
commit
0962394b84
|
@ -412,6 +412,18 @@ pub fn as_bytes_with_nul(&self) -> &[u8] {
|
||||||
/// Extracts a [`CStr`] slice containing the entire string.
|
/// Extracts a [`CStr`] slice containing the entire string.
|
||||||
///
|
///
|
||||||
/// [`CStr`]: struct.CStr.html
|
/// [`CStr`]: struct.CStr.html
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// #![feature(as_c_str)]
|
||||||
|
///
|
||||||
|
/// use std::ffi::{CString, CStr};
|
||||||
|
///
|
||||||
|
/// let c_string = CString::new(b"foo".to_vec()).unwrap();
|
||||||
|
/// let c_str = c_string.as_c_str();
|
||||||
|
/// assert_eq!(c_str, CStr::from_bytes_with_nul(b"foo\0").unwrap());
|
||||||
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "as_c_str", issue = "40380")]
|
#[unstable(feature = "as_c_str", issue = "40380")]
|
||||||
pub fn as_c_str(&self) -> &CStr {
|
pub fn as_c_str(&self) -> &CStr {
|
||||||
|
|
Loading…
Reference in a new issue