Skip to content

Commit

Permalink
Rollup merge of rust-lang#35182 - frewsxcv:nulerror, r=steveklabnik
Browse files Browse the repository at this point in the history
Add doc example for `std::ffi::NulError::nul_position`.

None
  • Loading branch information
GuillaumeGomez authored Aug 5, 2016
2 parents a935bda + 3081dd8 commit 59da56b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit 59da56b

Please sign in to comment.