Skip to content

Commit

Permalink
Manual implementation of Number's PartialEq.
Browse files Browse the repository at this point in the history
To please clippy.
  • Loading branch information
Timothée Haudebourg committed Oct 20, 2021
1 parent 10655c7 commit c3ac6c0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct Number {
}

#[cfg(not(feature = "arbitrary_precision"))]
#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone)]
enum N {
PosInt(u64),
/// Always less than zero.
Expand All @@ -31,6 +31,18 @@ enum N {
Float(f64),
}

#[cfg(not(feature = "arbitrary_precision"))]
impl PartialEq for N {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::PosInt(a), Self::PosInt(b)) => a == b,
(Self::NegInt(a), Self::NegInt(b)) => a == b,
(Self::Float(a), Self::Float(b)) => a == b,
_ => false,
}
}
}

// Implementing Eq is fine since any float values are always finite.
#[cfg(not(feature = "arbitrary_precision"))]
impl Eq for N {}
Expand Down

0 comments on commit c3ac6c0

Please sign in to comment.