]> git.lizzy.rs Git - rust.git/commitdiff
Add doc example for `std::ffi::NulError::nul_position`.
authorCorey Farwell <coreyf@rwell.org>
Tue, 2 Aug 2016 12:49:05 +0000 (08:49 -0400)
committerCorey Farwell <coreyf@rwell.org>
Tue, 2 Aug 2016 12:50:04 +0000 (08:50 -0400)
src/libstd/ffi/c_str.rs

index 0d3e18f9b966a2848781cafd10f2944d14ec2156..f800a6e228e9ba0f96bcf56f20e4ef63964cb3e8 100644 (file)
@@ -356,6 +356,18 @@ fn borrow(&self) -> &CStr { self }
 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 }