Skip to content

Commit

Permalink
fix(xlang-abi): impl Clone for CowStr
Browse files Browse the repository at this point in the history
  • Loading branch information
chorman0773 committed Nov 13, 2024
1 parent f380f92 commit 9cf0798
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions xlang/xlang_abi/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,20 @@ pub union CowStr<'a, A: Allocator = XLangAlloc> {
borrowed: CowStrView<'a>,
}

impl<'a, A: Allocator + Clone> Clone for CowStr<'a, A> {
fn clone(&self) -> Self {
if unsafe { self.borrowed.cap_sentinel } == usize::MAX {
Self {
borrowed: unsafe { self.borrowed },
}
} else {
Self {
owned: unsafe { self.owned.clone() },
}
}
}
}

impl<'a, A: Allocator> Default for CowStr<'a, A> {
fn default() -> Self {
Self::borrowed(StringView::new(""))
Expand Down

0 comments on commit 9cf0798

Please sign in to comment.