From e52d2f2ad0e0df9c2be02bc7bf99dd2324c78fd2 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 18 Jun 2017 16:12:39 -0700 Subject: [PATCH] Add doc example for `CStr::to_str`. --- src/libstd/ffi/c_str.rs | 9 +++++++++ 1 file changed, 9 insertions(+) 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 @@ 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()