diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-06-18 14:11:34 -0700 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2017-06-20 13:49:10 -0400 |
| commit | 0fad2e038a669aad7123f143cbb03ea6492b7e8e (patch) | |
| tree | f170164af25cae4fc5cb3972131305b1d5d37b70 /src/libstd | |
| parent | 29bce6e220f6fd2292d13d65fe503af7bf4852b7 (diff) | |
| download | rust-0fad2e038a669aad7123f143cbb03ea6492b7e8e.tar.gz rust-0fad2e038a669aad7123f143cbb03ea6492b7e8e.zip | |
Add doc example for `CStr::to_bytes`.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 74ac9d528bb..ecad407f261 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -800,6 +800,15 @@ impl CStr { /// > **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 /// > 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] #[stable(feature = "rust1", since = "1.0.0")] pub fn to_bytes(&self) -> &[u8] { |
