about summary refs log tree commit diff
path: root/src/libstd/ffi
diff options
context:
space:
mode:
authorAndrea Bedini <andrea@andreabedini.com>2016-01-19 16:29:53 +1100
committerAndrea Bedini <andrea@andreabedini.com>2016-01-19 16:29:53 +1100
commit0f8fc2cb8b4e81c630d0233d416b41e80beb22d6 (patch)
tree799f6364a65fcfac31f0978694aebe791fff05f4 /src/libstd/ffi
parent7a7307e5cf08ad25de62d4f9e13ddd58c59881c8 (diff)
downloadrust-0f8fc2cb8b4e81c630d0233d416b41e80beb22d6.tar.gz
rust-0f8fc2cb8b4e81c630d0233d416b41e80beb22d6.zip
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.
Diffstat (limited to 'src/libstd/ffi')
-rw-r--r--src/libstd/ffi/c_str.rs3
1 files changed, 1 insertions, 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());
     /// }
     /// # }
     /// ```