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
Jonathan Turner committed Aug 4, 2016
2 parents 72ed17b + 3081dd8 commit d07c5d2
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 d07c5d2

Please sign in to comment.