about summary refs log tree commit diff
path: root/src/libstd/ffi
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-06-18 16:12:39 -0700
committerCorey Farwell <coreyf@rwell.org>2017-06-20 13:49:42 -0400
commite52d2f2ad0e0df9c2be02bc7bf99dd2324c78fd2 (patch)
treee60e815c54672c98669fa08e18f4f516ff0325df /src/libstd/ffi
parent0962394b840f17a5dca584c8bd028d817ec986a2 (diff)
downloadrust-e52d2f2ad0e0df9c2be02bc7bf99dd2324c78fd2.tar.gz
rust-e52d2f2ad0e0df9c2be02bc7bf99dd2324c78fd2.zip
Add doc example for `CStr::to_str`.
Diffstat (limited to 'src/libstd/ffi')
-rw-r--r--src/libstd/ffi/c_str.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index 0ad4c74536a..8a7757fde88 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -894,6 +894,15 @@ impl CStr {
     /// > check whenever this method is called.
     ///
     /// [`&str`]: ../primitive.str.html
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CStr;
+    ///
+    /// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap();
+    /// assert_eq!(c_str.to_str(), Ok("foo"));
+    /// ```
     #[stable(feature = "cstr_to_str", since = "1.4.0")]
     pub fn to_str(&self) -> Result<&str, str::Utf8Error> {
         // NB: When CStr is changed to perform the length check in .to_bytes()