From 0f8fc2cb8b4e81c630d0233d416b41e80beb22d6 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Tue, 19 Jan 2016 16:29:53 +1100 Subject: [PATCH] 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. --- src/libstd/ffi/c_str.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index d6aa746f4cb..28f0b1fa967 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -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()); /// } /// # } /// ```