]> git.lizzy.rs Git - rust.git/commitdiff
Add doc example for `CString::as_c_str`.
authorCorey Farwell <coreyf@rwell.org>
Sun, 18 Jun 2017 23:05:00 +0000 (16:05 -0700)
committerCorey Farwell <coreyf@rwell.org>
Tue, 20 Jun 2017 17:49:42 +0000 (13:49 -0400)
src/libstd/ffi/c_str.rs

index b94a34b054c5784de3f3c55b5cafd3581990c700..0ad4c74536a8b220814069673e2e3d0aa9ea7c75 100644 (file)
@@ -412,6 +412,18 @@ pub fn as_bytes_with_nul(&self) -> &[u8] {
     /// Extracts a [`CStr`] slice containing the entire string.
     ///
     /// [`CStr`]: struct.CStr.html
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(as_c_str)]
+    ///
+    /// use std::ffi::{CString, CStr};
+    ///
+    /// let c_string = CString::new(b"foo".to_vec()).unwrap();
+    /// let c_str = c_string.as_c_str();
+    /// assert_eq!(c_str, CStr::from_bytes_with_nul(b"foo\0").unwrap());
+    /// ```
     #[inline]
     #[unstable(feature = "as_c_str", issue = "40380")]
     pub fn as_c_str(&self) -> &CStr {