Skip to content

Commit 8a923d4

Browse files
Rollup merge of rust-lang#35182 - frewsxcv:nulerror, r=steveklabnik
Add doc example for `std::ffi::NulError::nul_position`. None
2 parents 3ca18f7 + 3081dd8 commit 8a923d4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libstd/ffi/c_str.rs

Lines changed: 12 additions & 0 deletions
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)