about summary refs log tree commit diff
path: root/src/libstd/ffi
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2016-08-02 08:49:05 -0400
committerCorey Farwell <coreyf@rwell.org>2016-08-02 08:50:04 -0400
commit3081dd863718f941e283ec954f36a23bbe58ffeb (patch)
treec6a3d519c19ffd5816c6c79a758a0e28672b77c6 /src/libstd/ffi
parent97d5be98191038f24bf3c98f772cbf1662486581 (diff)
downloadrust-3081dd863718f941e283ec954f36a23bbe58ffeb.tar.gz
rust-3081dd863718f941e283ec954f36a23bbe58ffeb.zip
Add doc example for `std::ffi::NulError::nul_position`.
Diffstat (limited to 'src/libstd/ffi')
-rw-r--r--src/libstd/ffi/c_str.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index 0d3e18f9b96..f800a6e228e 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -356,6 +356,18 @@ impl Borrow<CStr> for CString {
 impl NulError {
     /// Returns the position of the nul byte in the slice that was provided to
     /// `CString::new`.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CString;
+    ///
+    /// let nul_error = CString::new("foo\0bar").unwrap_err();
+    /// assert_eq!(nul_error.nul_position(), 3);
+    ///
+    /// let nul_error = CString::new("foo bar\0").unwrap_err();
+    /// assert_eq!(nul_error.nul_position(), 7);
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn nul_position(&self) -> usize { self.0 }