Skip to content

Commit ae4832d

Browse files
committed
Add doc example for CString::as_bytes_with_nul.
1 parent 815c12a commit ae4832d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libstd/ffi/c_str.rs

+10
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,16 @@ impl CString {
381381
/// includes the trailing nul byte.
382382
///
383383
/// [`as_bytes`]: #method.as_bytes
384+
///
385+
/// # Examples
386+
///
387+
/// ```
388+
/// use std::ffi::CString;
389+
///
390+
/// let c_string = CString::new("foo").unwrap();
391+
/// let bytes = c_string.as_bytes_with_nul();
392+
/// assert_eq!(bytes, &[b'f', b'o', b'o', b'\0']);
393+
/// ```
384394
#[stable(feature = "rust1", since = "1.0.0")]
385395
pub fn as_bytes_with_nul(&self) -> &[u8] {
386396
&self.inner

0 commit comments

Comments
 (0)