We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 79e0543 commit d48a869Copy full SHA for d48a869
library/core/src/ffi/c_str.rs
@@ -65,9 +65,9 @@ use crate::str;
65
/// extern "C" { fn my_string() -> *const c_char; }
66
///
67
/// fn my_string_safe() -> String {
68
-/// unsafe {
69
-/// String::from_utf8_lossy(CStr::from_ptr(my_string()))
70
-/// }
+/// 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()
71
/// }
72
73
/// println!("string: {}", my_string_safe());
0 commit comments