Skip to content

Commit

Permalink
Add doc example for CString::as_bytes_with_nul.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Jun 6, 2017
1 parent 815c12a commit ae4832d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/libstd/ffi/c_str.rs
Expand Up @@ -381,6 +381,16 @@ impl CString {
/// includes the trailing nul byte.
///
/// [`as_bytes`]: #method.as_bytes
///
/// # Examples
///
/// ```
/// use std::ffi::CString;
///
/// let c_string = CString::new("foo").unwrap();
/// let bytes = c_string.as_bytes_with_nul();
/// assert_eq!(bytes, &[b'f', b'o', b'o', b'\0']);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_bytes_with_nul(&self) -> &[u8] {
&self.inner
Expand Down

0 comments on commit ae4832d

Please sign in to comment.