]> git.lizzy.rs Git - rust.git/commitdiff
Improve CStr::from_ptr example in docs
authorAndrea Bedini <andrea@andreabedini.com>
Tue, 19 Jan 2016 05:29:53 +0000 (16:29 +1100)
committerAndrea Bedini <andrea@andreabedini.com>
Tue, 19 Jan 2016 05:29:53 +0000 (16:29 +1100)
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

index d6aa746f4cb5333ed1eec65adf8dd0cb1872be13..28f0b1fa9674b10d411858a9d56a9578877c7ae0 100644 (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());
     /// }
     /// # }
     /// ```