Skip to content

Commit

Permalink
Add error scenario doc examples for CStr::from_bytes_with_nul.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Jun 20, 2017
1 parent 7f687f8 commit 5d71e8c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libstd/ffi/c_str.rs
Expand Up @@ -708,6 +708,24 @@ impl CStr {
/// let cstr = CStr::from_bytes_with_nul(b"hello\0");
/// assert!(cstr.is_ok());
/// ```
///
/// Creating a `CStr` without a trailing nul byte is an error:
///
/// ```
/// use std::ffi::CStr;
///
/// let c_str = CStr::from_bytes_with_nul(b"hello");
/// assert!(c_str.is_err());
/// ```
///
/// Creating a `CStr` with an interior nul byte is an error:
///
/// ```
/// use std::ffi::CStr;
///
/// let c_str = CStr::from_bytes_with_nul(b"he\0llo\0");
/// assert!(c_str.is_err());
/// ```
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
pub fn from_bytes_with_nul(bytes: &[u8])
-> Result<&CStr, FromBytesWithNulError> {
Expand Down

0 comments on commit 5d71e8c

Please sign in to comment.