We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 31e5acd commit 8db65bbCopy full SHA for 8db65bb
src/compact_cow_str.rs
@@ -96,6 +96,21 @@ impl<'a> CompactCowStr<'a> {
96
None
97
}
98
99
+
100
+ /// Convert into `String`, re-using the memory allocation it was already owned.
101
+ #[inline]
102
+ pub fn into_owned(self) -> String {
103
+ unsafe {
104
+ let raw = self.as_raw_str();
105
+ let is_borrowed = self.is_borrowed();
106
+ mem::forget(self);
107
+ if is_borrowed {
108
+ String::from(&*raw)
109
+ } else {
110
+ Box::from_raw(raw as *mut str).into_string()
111
+ }
112
113
114
115
116
impl<'a> Clone for CompactCowStr<'a> {
0 commit comments