From: Corey Farwell Date: Tue, 6 Jun 2017 03:48:13 +0000 (-0400) Subject: Add doc example for `CString::into_bytes_with_nul`. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=815c12a7657cfc68c7058f83d9c30ff7607c17b2;p=rust.git Add doc example for `CString::into_bytes_with_nul`. --- diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 0e8d72c5f3b..81563a59064 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -353,6 +353,16 @@ pub fn into_bytes(self) -> Vec { /// 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 { self.into_inner().into_vec()