Skip to content

Commit 815c12a

Browse files
committed
Add doc example for CString::into_bytes_with_nul.
1 parent 3ec1f61 commit 815c12a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libstd/ffi/c_str.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,16 @@ impl CString {
353353
/// includes the trailing nul byte.
354354
///
355355
/// [`into_bytes`]: #method.into_bytes
356+
///
357+
/// # Examples
358+
///
359+
/// ```
360+
/// use std::ffi::CString;
361+
///
362+
/// let c_string = CString::new("foo").unwrap();
363+
/// let bytes = c_string.into_bytes_with_nul();
364+
/// assert_eq!(bytes, vec![b'f', b'o', b'o', b'\0']);
365+
/// ```
356366
#[stable(feature = "cstring_into", since = "1.7.0")]
357367
pub fn into_bytes_with_nul(self) -> Vec<u8> {
358368
self.into_inner().into_vec()

0 commit comments

Comments
 (0)