Improve CStr::from_ptr example in docs
Documentation of `CStr::from_ptr` suggests using `str::from_utf8(slice.to_bytes()).unwrap()` to obtain a `&str` but `CStr` has `CStr::to_str` that does exactly that.
This commit is contained in:
parent
7a7307e5cf
commit
0f8fc2cb8b
@ -415,8 +415,7 @@ impl CStr {
|
||||
///
|
||||
/// unsafe {
|
||||
/// let slice = CStr::from_ptr(my_string());
|
||||
/// println!("string returned: {}",
|
||||
/// str::from_utf8(slice.to_bytes()).unwrap());
|
||||
/// println!("string returned: {}", slice.to_str().unwrap());
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
|
Loading…
Reference in New Issue
Block a user