mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-20 10:55:14 +00:00
Rollup merge of #99781 - workingjubilee:demo-string-from-cstr, r=thomcc
Use String::from_utf8_lossy in CStr demo Fixes rust-lang/rust#99755.
This commit is contained in:
commit
9b3f49f1bd
@ -65,9 +65,9 @@ use crate::str;
|
||||
/// extern "C" { fn my_string() -> *const c_char; }
|
||||
///
|
||||
/// fn my_string_safe() -> String {
|
||||
/// unsafe {
|
||||
/// CStr::from_ptr(my_string()).to_string_lossy().into_owned()
|
||||
/// }
|
||||
/// let cstr = unsafe { CStr::from_ptr(my_string()) };
|
||||
/// // Get copy-on-write Cow<'_, str>, then guarantee a freshly-owned String allocation
|
||||
/// String::from_utf8_lossy(cstr.to_bytes()).to_string()
|
||||
/// }
|
||||
///
|
||||
/// println!("string: {}", my_string_safe());
|
||||
|
Loading…
Reference in New Issue
Block a user