Rollup merge of #31019 - andreabedini:patch-1, r=alexcrichton
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. (First PR, be nice :)
This commit is contained in:
commit
03b4bf20f6
@ -407,7 +407,6 @@ impl CStr {
|
||||
/// # fn main() {
|
||||
/// use std::ffi::CStr;
|
||||
/// use std::os::raw::c_char;
|
||||
/// use std::str;
|
||||
///
|
||||
/// extern {
|
||||
/// fn my_string() -> *const c_char;
|
||||
@ -415,8 +414,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