Skip to content

Commit 7f687f8

Browse files
committed
Add doc example for CStr::to_bytes_with_nul.
1 parent 0fad2e0 commit 7f687f8

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
@@ -826,6 +826,15 @@ impl CStr {
826826
/// > length calculation whenever this method is called.
827827
///
828828
/// [`to_bytes`]: #method.to_bytes
829+
///
830+
/// # Examples
831+
///
832+
/// ```
833+
/// use std::ffi::CStr;
834+
///
835+
/// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap();
836+
/// assert_eq!(c_str.to_bytes_with_nul(), b"foo\0");
837+
/// ```
829838
#[inline]
830839
#[stable(feature = "rust1", since = "1.0.0")]
831840
pub fn to_bytes_with_nul(&self) -> &[u8] {

0 commit comments

Comments
 (0)