提交 03b4bf20 编写于 作者: S Steve Klabnik

Rollup merge of #31019 - andreabedini:patch-1, r=alexcrichton

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.

(First PR, be nice :)
......@@ -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;
......@@ -415,8 +414,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());
/// }
/// # }
/// ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册