From 06f63f5edb887aaff70a475de904103119d022e3 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 5 Jun 2017 23:50:49 -0400 Subject: [PATCH] Add doc example for `CString::as_bytes`. --- src/libstd/ffi/c_str.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 21e4779fc3a..2d78f0511d6 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -372,6 +372,16 @@ pub fn into_bytes_with_nul(self) -> Vec { /// /// The returned slice does **not** contain the trailing nul separator and /// it is guaranteed to not have any interior nul bytes. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// let bytes = c_string.as_bytes(); + /// assert_eq!(bytes, &[b'f', b'o', b'o']); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn as_bytes(&self) -> &[u8] { &self.inner[..self.inner.len() - 1] -- 2.44.0