We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
std::ffi::NulError::nul_position
1 parent 97d5be9 commit 3081dd8Copy full SHA for 3081dd8
src/libstd/ffi/c_str.rs
@@ -356,6 +356,18 @@ impl Borrow<CStr> for CString {
356
impl NulError {
357
/// Returns the position of the nul byte in the slice that was provided to
358
/// `CString::new`.
359
+ ///
360
+ /// # Examples
361
362
+ /// ```
363
+ /// use std::ffi::CString;
364
365
+ /// let nul_error = CString::new("foo\0bar").unwrap_err();
366
+ /// assert_eq!(nul_error.nul_position(), 3);
367
368
+ /// let nul_error = CString::new("foo bar\0").unwrap_err();
369
+ /// assert_eq!(nul_error.nul_position(), 7);
370
371
#[stable(feature = "rust1", since = "1.0.0")]
372
pub fn nul_position(&self) -> usize { self.0 }
373
0 commit comments