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