about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-06-18 16:05:00 -0700
committerCorey Farwell <coreyf@rwell.org>2017-06-20 13:49:42 -0400
commit0962394b840f17a5dca584c8bd028d817ec986a2 (patch)
treef4bd2f053e967b4f17f15dfd7c1138b9625bd2dd /src/libstd
parent65793b30d35273c57767714ddf61e0360c64dea1 (diff)
downloadrust-0962394b840f17a5dca584c8bd028d817ec986a2.tar.gz
rust-0962394b840f17a5dca584c8bd028d817ec986a2.zip
Add doc example for `CString::as_c_str`.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/ffi/c_str.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index b94a34b054c..0ad4c74536a 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -412,6 +412,18 @@ impl CString {
     /// 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 {