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

index 0e8d72c5f3be2e58ec299da688aa63e03257db7f..81563a5906448f46c118a9f547331dafd23f359b 100644 (file)
@@ -353,6 +353,16 @@ pub fn into_bytes(self) -> Vec<u8> {
     /// includes the trailing nul byte.
     ///
     /// [`into_bytes`]: #method.into_bytes
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CString;
+    ///
+    /// let c_string = CString::new("foo").unwrap();
+    /// let bytes = c_string.into_bytes_with_nul();
+    /// assert_eq!(bytes, vec![b'f', b'o', b'o', b'\0']);
+    /// ```
     #[stable(feature = "cstring_into", since = "1.7.0")]
     pub fn into_bytes_with_nul(self) -> Vec<u8> {
         self.into_inner().into_vec()