mirror of
https://github.com/rust-lang/rust
synced 2024-09-15 22:50:55 +00:00
Add doc example for CStr::to_str
.
This commit is contained in:
parent
0962394b84
commit
e52d2f2ad0
|
@ -894,6 +894,15 @@ pub fn to_bytes_with_nul(&self) -> &[u8] {
|
||||||
/// > check whenever this method is called.
|
/// > check whenever this method is called.
|
||||||
///
|
///
|
||||||
/// [`&str`]: ../primitive.str.html
|
/// [`&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")]
|
#[stable(feature = "cstr_to_str", since = "1.4.0")]
|
||||||
pub fn to_str(&self) -> Result<&str, str::Utf8Error> {
|
pub fn to_str(&self) -> Result<&str, str::Utf8Error> {
|
||||||
// NB: When CStr is changed to perform the length check in .to_bytes()
|
// NB: When CStr is changed to perform the length check in .to_bytes()
|
||||||
|
|
Loading…
Reference in a new issue