Rollup merge of #140297 - shepmaster:cstr-lossy, r=joboet

Update example to use CStr::to_string_lossy
This commit is contained in:
Matthias Krüger
2025-04-27 11:54:58 +02:00
committed by GitHub
+3 -2
View File
@@ -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());