Add doc example for `CStr::to_bytes`.
This commit is contained in:
parent
29bce6e220
commit
0fad2e038a
|
@ -800,6 +800,15 @@ impl CStr {
|
||||||
/// > **Note**: This method is currently implemented as a 0-cost cast, but
|
/// > **Note**: This method is currently implemented as a 0-cost cast, but
|
||||||
/// > it is planned to alter its definition in the future to perform the
|
/// > it is planned to alter its definition in the future to perform the
|
||||||
/// > length calculation whenever this method is called.
|
/// > length calculation whenever this method is called.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use std::ffi::CStr;
|
||||||
|
///
|
||||||
|
/// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap();
|
||||||
|
/// assert_eq!(c_str.to_bytes(), b"foo");
|
||||||
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn to_bytes(&self) -> &[u8] {
|
pub fn to_bytes(&self) -> &[u8] {
|
||||||
|
|
Loading…
Reference in New Issue