Skip to content

Commit 3ec1f61

Browse files
committed
Add doc example for CString::into_bytes.
1 parent 4db8c9f commit 3ec1f61

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
@@ -331,6 +331,16 @@ impl CString {
331331
///
332332
/// The returned buffer does **not** contain the trailing nul separator and
333333
/// it is guaranteed to not have any interior nul bytes.
334+
///
335+
/// # Examples
336+
///
337+
/// ```
338+
/// use std::ffi::CString;
339+
///
340+
/// let c_string = CString::new("foo").unwrap();
341+
/// let bytes = c_string.into_bytes();
342+
/// assert_eq!(bytes, vec![b'f', b'o', b'o']);
343+
/// ```
334344
#[stable(feature = "cstring_into", since = "1.7.0")]
335345
pub fn into_bytes(self) -> Vec<u8> {
336346
let mut vec = self.into_inner().into_vec();

0 commit comments

Comments
 (0)