]> git.lizzy.rs Git - rust.git/commitdiff
Add doc example for `CStr::to_bytes`.
authorCorey Farwell <coreyf@rwell.org>
Sun, 18 Jun 2017 21:11:34 +0000 (14:11 -0700)
committerCorey Farwell <coreyf@rwell.org>
Tue, 20 Jun 2017 17:49:10 +0000 (13:49 -0400)
src/libstd/ffi/c_str.rs

index 74ac9d528bb626102eae7ae708b8885db43f85f5..ecad407f261ed127d767013da337e92867f8c4f7 100644 (file)
@@ -800,6 +800,15 @@ pub fn as_ptr(&self) -> *const c_char {
     /// > **Note**: This method is currently implemented as a 0-cost cast, but
     /// > it is planned to alter its definition in the future to perform the
     /// > length calculation whenever this method is called.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CStr;
+    ///
+    /// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap();
+    /// assert_eq!(c_str.to_bytes(), b"foo");
+    /// ```
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn to_bytes(&self) -> &[u8] {