diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-06-05 23:50:49 -0400 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2017-06-05 23:50:49 -0400 |
| commit | 06f63f5edb887aaff70a475de904103119d022e3 (patch) | |
| tree | fa8ea79d79cd02acdcfbef73be5fe716b741837c /src/libstd/ffi | |
| parent | ae4832d48acc563a55e23190e03f75e9e3336293 (diff) | |
| download | rust-06f63f5edb887aaff70a475de904103119d022e3.tar.gz rust-06f63f5edb887aaff70a475de904103119d022e3.zip | |
Add doc example for `CString::as_bytes`.
Diffstat (limited to 'src/libstd/ffi')
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 21e4779fc3a..2d78f0511d6 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -372,6 +372,16 @@ impl CString { /// /// The returned slice does **not** contain the trailing nul separator and /// it is guaranteed to not have any interior nul bytes. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// let bytes = c_string.as_bytes(); + /// assert_eq!(bytes, &[b'f', b'o', b'o']); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn as_bytes(&self) -> &[u8] { &self.inner[..self.inner.len() - 1] |
