mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #140297 - shepmaster:cstr-lossy, r=joboet
Update example to use CStr::to_string_lossy
This commit is contained in:
@@ -79,8 +79,9 @@
|
||||
///
|
||||
/// fn my_string_safe() -> String {
|
||||
/// 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()
|
||||
/// // Get a copy-on-write Cow<'_, str>, then extract the
|
||||
/// // allocated String (or allocate a fresh one if needed).
|
||||
/// cstr.to_string_lossy().into_owned()
|
||||
/// }
|
||||
///
|
||||
/// println!("string: {}", my_string_safe());
|
||||
|
||||
Reference in New Issue
Block a user