about summary refs log tree commit diff
path: root/src/libstd/ffi
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-06-05 23:48:13 -0400
committerCorey Farwell <coreyf@rwell.org>2017-06-05 23:48:13 -0400
commit815c12a7657cfc68c7058f83d9c30ff7607c17b2 (patch)
tree5779467e75bc98045fcb99b558b2865fdee9dc73 /src/libstd/ffi
parent3ec1f61accd0386d6923102bd2da30fef4603c47 (diff)
downloadrust-815c12a7657cfc68c7058f83d9c30ff7607c17b2.tar.gz
rust-815c12a7657cfc68c7058f83d9c30ff7607c17b2.zip
Add doc example for `CString::into_bytes_with_nul`.
Diffstat (limited to 'src/libstd/ffi')
-rw-r--r--src/libstd/ffi/c_str.rs10
1 files changed, 10 insertions, 0 deletions
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 @@ impl CString {
     /// 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()