Skip to content

Commit 4f00383

Browse files
committed
Rollup merge of rust-lang#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 :)
2 parents 68e51c3 + 6849b6d commit 4f00383

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/libstd/ffi/c_str.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,14 @@ impl CStr {
407407
/// # fn main() {
408408
/// use std::ffi::CStr;
409409
/// use std::os::raw::c_char;
410-
/// use std::str;
411410
///
412411
/// extern {
413412
/// fn my_string() -> *const c_char;
414413
/// }
415414
///
416415
/// unsafe {
417416
/// let slice = CStr::from_ptr(my_string());
418-
/// println!("string returned: {}",
419-
/// str::from_utf8(slice.to_bytes()).unwrap());
417+
/// println!("string returned: {}", slice.to_str().unwrap());
420418
/// }
421419
/// # }
422420
/// ```

0 commit comments

Comments
 (0)