Skip to content

Commit

Permalink
Add doc example for CString::as_c_str.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Jun 20, 2017
1 parent 65793b3 commit 0962394
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/libstd/ffi/c_str.rs
Expand Up @@ -412,6 +412,18 @@ impl CString {
/// Extracts a [`CStr`] slice containing the entire string.
///
/// [`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]
#[unstable(feature = "as_c_str", issue = "40380")]
pub fn as_c_str(&self) -> &CStr {
Expand Down

0 comments on commit 0962394

Please sign in to comment.