From 7f687f8602e1d3d8290c154ec67bb8fbd5f493d7 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 18 Jun 2017 14:12:17 -0700 Subject: [PATCH] Add doc example for `CStr::to_bytes_with_nul`. --- 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 ecad407f261..8b18b2f1255 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -826,6 +826,15 @@ impl CStr { /// > length calculation whenever this method is called. /// /// [`to_bytes`]: #method.to_bytes + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CStr; + /// + /// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap(); + /// assert_eq!(c_str.to_bytes_with_nul(), b"foo\0"); + /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn to_bytes_with_nul(&self) -> &[u8] {