1
Fork 0

Force the Cow into a String

This commit is contained in:
Jubilee Young 2022-07-26 14:10:26 -07:00
parent 79e0543060
commit d48a869b9d

View file

@ -65,9 +65,9 @@ use crate::str;
/// extern "C" { fn my_string() -> *const c_char; } /// extern "C" { fn my_string() -> *const c_char; }
/// ///
/// fn my_string_safe() -> String { /// fn my_string_safe() -> String {
/// unsafe { /// let cstr = unsafe { CStr::from_ptr(my_string()) };
/// String::from_utf8_lossy(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()); /// println!("string: {}", my_string_safe());