about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-06-18 14:28:10 -0700
committerCorey Farwell <coreyf@rwell.org>2017-06-20 13:49:27 -0400
commit5d71e8cd7e25423e15400eaeb1bf6e4bf545c8e0 (patch)
tree547d4df5082fce1cdef07d9128016b00b79f5fa6 /src/libstd
parent7f687f8602e1d3d8290c154ec67bb8fbd5f493d7 (diff)
downloadrust-5d71e8cd7e25423e15400eaeb1bf6e4bf545c8e0.tar.gz
rust-5d71e8cd7e25423e15400eaeb1bf6e4bf545c8e0.zip
Add error scenario doc examples for `CStr::from_bytes_with_nul`.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/ffi/c_str.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index 8b18b2f1255..ea0748d31e9 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -708,6 +708,24 @@ impl CStr {
     /// let cstr = CStr::from_bytes_with_nul(b"hello\0");
     /// assert!(cstr.is_ok());
     /// ```
+    ///
+    /// Creating a `CStr` without a trailing nul byte is an error:
+    ///
+    /// ```
+    /// use std::ffi::CStr;
+    ///
+    /// let c_str = CStr::from_bytes_with_nul(b"hello");
+    /// assert!(c_str.is_err());
+    /// ```
+    ///
+    /// Creating a `CStr` with an interior nul byte is an error:
+    ///
+    /// ```
+    /// use std::ffi::CStr;
+    ///
+    /// let c_str = CStr::from_bytes_with_nul(b"he\0llo\0");
+    /// assert!(c_str.is_err());
+    /// ```
     #[stable(feature = "cstr_from_bytes", since = "1.10.0")]
     pub fn from_bytes_with_nul(bytes: &[u8])
                                -> Result<&CStr, FromBytesWithNulError> {