Navigation Menu

Skip to content

Commit

Permalink
Add doc example for CStr::to_str.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Jun 20, 2017
1 parent 0962394 commit e52d2f2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/libstd/ffi/c_str.rs
Expand Up @@ -894,6 +894,15 @@ impl CStr {
/// > check whenever this method is called.
///
/// [`&str`]: ../primitive.str.html
///
/// # Examples
///
/// ```
/// use std::ffi::CStr;
///
/// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap();
/// assert_eq!(c_str.to_str(), Ok("foo"));
/// ```
#[stable(feature = "cstr_to_str", since = "1.4.0")]
pub fn to_str(&self) -> Result<&str, str::Utf8Error> {
// NB: When CStr is changed to perform the length check in .to_bytes()
Expand Down

0 comments on commit e52d2f2

Please sign in to comment.