Skip to content

Commit b3d309b

Browse files
authored
Rollup merge of #35182 - frewsxcv:nulerror, r=steveklabnik
Add doc example for `std::ffi::NulError::nul_position`. None
2 parents 249bf1c + 3081dd8 commit b3d309b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libstd/ffi/c_str.rs

+12
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,18 @@ impl Borrow<CStr> for CString {
356356
impl NulError {
357357
/// Returns the position of the nul byte in the slice that was provided to
358358
/// `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+
/// ```
359371
#[stable(feature = "rust1", since = "1.0.0")]
360372
pub fn nul_position(&self) -> usize { self.0 }
361373

0 commit comments

Comments
 (0)