Add doc example for std::ffi::NulError::nul_position.
This commit is contained in:
parent
97d5be9819
commit
3081dd8637
1 changed files with 12 additions and 0 deletions
|
|
@ -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 }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue