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

index a1ce02b583057a2623eebdf8e1a015c279e4c5ad..0e8d72c5f3be2e58ec299da688aa63e03257db7f 100644 (file)
@@ -331,6 +331,16 @@ pub fn into_string(self) -> Result<String, IntoStringError> {
     ///
     /// The returned buffer 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.into_bytes();
+    /// assert_eq!(bytes, vec![b'f', b'o', b'o']);
+    /// ```
     #[stable(feature = "cstring_into", since = "1.7.0")]
     pub fn into_bytes(self) -> Vec<u8> {
         let mut vec = self.into_inner().into_vec();