]> git.lizzy.rs Git - rust.git/commitdiff
Add doc example for `CString::as_bytes`.
authorCorey Farwell <coreyf@rwell.org>
Tue, 6 Jun 2017 03:50:49 +0000 (23:50 -0400)
committerCorey Farwell <coreyf@rwell.org>
Tue, 6 Jun 2017 03:50:49 +0000 (23:50 -0400)
src/libstd/ffi/c_str.rs

index 21e4779fc3a2b9d6dee3730bb3a5571cbff63839..2d78f0511d6d763b2ccc953159e1e6b8745f3e09 100644 (file)
@@ -372,6 +372,16 @@ pub fn into_bytes_with_nul(self) -> Vec<u8> {
     ///
     /// 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]