From ae4832d48acc563a55e23190e03f75e9e3336293 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 5 Jun 2017 23:49:52 -0400 Subject: [PATCH] Add doc example for `CString::as_bytes_with_nul`. --- 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 81563a5906448..21e4779fc3a2b 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -381,6 +381,16 @@ impl CString { /// includes the trailing nul byte. /// /// [`as_bytes`]: #method.as_bytes + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// let bytes = c_string.as_bytes_with_nul(); + /// assert_eq!(bytes, &[b'f', b'o', b'o', b'\0']); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn as_bytes_with_nul(&self) -> &[u8] { &self.inner