Skip to content

Commit 06f63f5

Browse files
committed
Add doc example for CString::as_bytes.
1 parent ae4832d commit 06f63f5

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
@@ -372,6 +372,16 @@ impl CString {
372372
///
373373
/// The returned slice does **not** contain the trailing nul separator and
374374
/// it is guaranteed to not have any interior nul bytes.
375+
///
376+
/// # Examples
377+
///
378+
/// ```
379+
/// use std::ffi::CString;
380+
///
381+
/// let c_string = CString::new("foo").unwrap();
382+
/// let bytes = c_string.as_bytes();
383+
/// assert_eq!(bytes, &[b'f', b'o', b'o']);
384+
/// ```
375385
#[stable(feature = "rust1", since = "1.0.0")]
376386
pub fn as_bytes(&self) -> &[u8] {
377387
&self.inner[..self.inner.len() - 1]

0 commit comments

Comments
 (0)