Skip to content

Commit 0f8fc2c

Browse files
committed
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.
1 parent 7a7307e commit 0f8fc2c

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/libstd/ffi/c_str.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,7 @@ impl CStr {
415415
///
416416
/// unsafe {
417417
/// let slice = CStr::from_ptr(my_string());
418-
/// println!("string returned: {}",
419-
/// str::from_utf8(slice.to_bytes()).unwrap());
418+
/// println!("string returned: {}", slice.to_str().unwrap());
420419
/// }
421420
/// # }
422421
/// ```

0 commit comments

Comments
 (0)