Skip to content

Commit

Permalink
Add clone_from implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Mar 8, 2024
1 parent f4c8df1 commit 386e483
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ impl<T: Clone, LenT: ValidLength> Clone for FixedArray<T, LenT> {
// SAFETY: The Box::from cannot make the length mismatch.
unsafe { Self::from_box_with_nonzero(ptr, self.len) }
}

fn clone_from(&mut self, source: &Self) {
if self.len() == source.len() {
self.clone_from_slice(source);
} else {
*self = source.clone();
}
}
}

impl<T, LenT: ValidLength> core::ops::Index<LenT> for FixedArray<T, LenT> {
Expand Down
7 changes: 7 additions & 0 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ impl<LenT: ValidLength> Clone for FixedString<LenT> {
FixedStringRepr::Static(a) => Self(FixedStringRepr::Static(*a)),
}
}

fn clone_from(&mut self, source: &Self) {
match (&mut self.0, &source.0) {
(FixedStringRepr::Heap(new), FixedStringRepr::Heap(src)) => new.clone_from(src),
_ => *self = source.clone(),
}
}
}

impl<LenT: ValidLength> Hash for FixedString<LenT> {
Expand Down

0 comments on commit 386e483

Please sign in to comment.