From 0f8fc2cb8b4e81c630d0233d416b41e80beb22d6 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Tue, 19 Jan 2016 16:29:53 +1100 Subject: [PATCH 1/2] 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()); /// } /// # } /// ``` From 6849b6dc95266df9dbe6e1fc33c27c6b4dc08c13 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Wed, 20 Jan 2016 10:38:29 +1100 Subject: [PATCH 2/2] Remove leftover import of `std::str` in doc test --- src/libstd/ffi/c_str.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 28f0b1fa967..9d505607a60 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -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;