Remove expects from FullInt Partial{Ord,Eq}

This commit is contained in:
Michael Wright 2021-10-30 06:22:19 +02:00
parent 4c70c182c0
commit 665ff57fde

View File

@ -246,27 +246,26 @@ impl FullInt {
impl PartialEq for FullInt { impl PartialEq for FullInt {
#[must_use] #[must_use]
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.partial_cmp(other).expect("`partial_cmp` only returns `Some(_)`") == Ordering::Equal self.cmp(other) == Ordering::Equal
} }
} }
impl PartialOrd for FullInt { impl PartialOrd for FullInt {
#[must_use] #[must_use]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(match (self, other) { Some(self.cmp(other))
(&Self::S(s), &Self::S(o)) => s.cmp(&o),
(&Self::U(s), &Self::U(o)) => s.cmp(&o),
(&Self::S(s), &Self::U(o)) => Self::cmp_s_u(s, o),
(&Self::U(s), &Self::S(o)) => Self::cmp_s_u(o, s).reverse(),
})
} }
} }
impl Ord for FullInt { impl Ord for FullInt {
#[must_use] #[must_use]
fn cmp(&self, other: &Self) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
self.partial_cmp(other) match (self, other) {
.expect("`partial_cmp` for FullInt can never return `None`") (&Self::S(s), &Self::S(o)) => s.cmp(&o),
(&Self::U(s), &Self::U(o)) => s.cmp(&o),
(&Self::S(s), &Self::U(o)) => Self::cmp_s_u(s, o),
(&Self::U(s), &Self::S(o)) => Self::cmp_s_u(o, s).reverse(),
}
} }
} }