Skip to content

Commit 0fad2e0

Browse files
committed
Add doc example for CStr::to_bytes.
1 parent 29bce6e commit 0fad2e0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/libstd/ffi/c_str.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,15 @@ impl CStr {
800800
/// > **Note**: This method is currently implemented as a 0-cost cast, but
801801
/// > it is planned to alter its definition in the future to perform the
802802
/// > length calculation whenever this method is called.
803+
///
804+
/// # Examples
805+
///
806+
/// ```
807+
/// use std::ffi::CStr;
808+
///
809+
/// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap();
810+
/// assert_eq!(c_str.to_bytes(), b"foo");
811+
/// ```
803812
#[inline]
804813
#[stable(feature = "rust1", since = "1.0.0")]
805814
pub fn to_bytes(&self) -> &[u8] {

0 commit comments

Comments
 (0)