diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-04-27 11:54:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-27 11:54:58 +0200 |
| commit | 3af00f0889907d27234de1952c73764f922d60df (patch) | |
| tree | 132cc5ba9c9228dc784345de0183e1c4c81c3fed | |
| parent | 766340b26e7f00c9d32be4918c918724a82bd030 (diff) | |
| parent | 9112c86f4226a6922f07bb44b49cedb75d1ee2f9 (diff) | |
| download | rust-3af00f0889907d27234de1952c73764f922d60df.tar.gz rust-3af00f0889907d27234de1952c73764f922d60df.zip | |
Rollup merge of #140297 - shepmaster:cstr-lossy, r=joboet
Update example to use CStr::to_string_lossy
| -rw-r--r-- | library/core/src/ffi/c_str.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 85e87445a1b..ac07c645c01 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -79,8 +79,9 @@ use crate::{fmt, ops, slice, str}; /// /// 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()); |
