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

index 0ad4c74536a8b220814069673e2e3d0aa9ea7c75..8a7757fde882b76c38ad847f2e8ba6e4c2d2e4f0 100644 (file)
@@ -894,6 +894,15 @@ pub fn to_bytes_with_nul(&self) -> &[u8] {
     /// > 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()