Skip to content

Commit 0962394

Browse files
committed
Add doc example for CString::as_c_str.
1 parent 65793b3 commit 0962394

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
@@ -412,6 +412,18 @@ impl CString {
412412
/// Extracts a [`CStr`] slice containing the entire string.
413413
///
414414
/// [`CStr`]: struct.CStr.html
415+
///
416+
/// # Examples
417+
///
418+
/// ```
419+
/// #![feature(as_c_str)]
420+
///
421+
/// use std::ffi::{CString, CStr};
422+
///
423+
/// let c_string = CString::new(b"foo".to_vec()).unwrap();
424+
/// let c_str = c_string.as_c_str();
425+
/// assert_eq!(c_str, CStr::from_bytes_with_nul(b"foo\0").unwrap());
426+
/// ```
415427
#[inline]
416428
#[unstable(feature = "as_c_str", issue = "40380")]
417429
pub fn as_c_str(&self) -> &CStr {

0 commit comments

Comments
 (0)