Skip to content

Commit

Permalink
Rollup merge of #99781 - workingjubilee:demo-string-from-cstr, r=thomcc
Browse files Browse the repository at this point in the history
Use String::from_utf8_lossy in CStr demo

Fixes #99755.
  • Loading branch information
JohnTitor committed Jul 29, 2022
2 parents 55296c4 + d48a869 commit 9b3f49f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 9b3f49f

Please sign in to comment.