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:
Andrea Bedini 2016-01-19 16:29:53 +11:00
parent 7a7307e5cf
commit 0f8fc2cb8b

View File

@ -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());
/// }
/// # }
/// ```