diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-06-05 23:49:52 -0400 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2017-06-05 23:49:52 -0400 |
| commit | ae4832d48acc563a55e23190e03f75e9e3336293 (patch) | |
| tree | 468f36232b015e17998a8c496cf221fcb00dcbd2 /src/libstd | |
| parent | 815c12a7657cfc68c7058f83d9c30ff7607c17b2 (diff) | |
| download | rust-ae4832d48acc563a55e23190e03f75e9e3336293.tar.gz rust-ae4832d48acc563a55e23190e03f75e9e3336293.zip | |
Add doc example for `CString::as_bytes_with_nul`.
Diffstat (limited to 'src/libstd')
| -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 81563a59064..21e4779fc3a 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -381,6 +381,16 @@ impl CString { /// includes the trailing nul byte. /// /// [`as_bytes`]: #method.as_bytes + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// let bytes = c_string.as_bytes_with_nul(); + /// assert_eq!(bytes, &[b'f', b'o', b'o', b'\0']); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn as_bytes_with_nul(&self) -> &[u8] { &self.inner |
