Don't panic, when merging identical full objects

This commit is contained in:
Hanno Braun 2022-11-08 13:42:03 +01:00
parent 8ede469d00
commit 41b32978b7
1 changed files with 8 additions and 2 deletions

View File

@ -67,8 +67,14 @@ impl<T: HasPartial> MaybePartial<T> {
/// Merge this `MaybePartial` with another of the same type /// Merge this `MaybePartial` with another of the same type
pub fn merge_with(self, other: impl Into<Self>) -> Self { pub fn merge_with(self, other: impl Into<Self>) -> Self {
match (self, other.into()) { match (self, other.into()) {
(Self::Full(_), Self::Full(_)) => { (Self::Full(a), Self::Full(b)) => {
panic!("Can't merge two full objects") if a.id() != b.id() {
panic!("Can't merge two full objects")
}
// If they're equal, which they are, if we reach this point,
// then merging them is a no-op.
Self::Full(a)
} }
(Self::Full(full), Self::Partial(_)) (Self::Full(full), Self::Partial(_))
| (Self::Partial(_), Self::Full(full)) => Self::Full(full), | (Self::Partial(_), Self::Full(full)) => Self::Full(full),