We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 55296c4 + d48a869 commit 9b3f49fCopy full SHA for 9b3f49f
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
-/// CStr::from_ptr(my_string()).to_string_lossy().into_owned()
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