-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…standard-traits NAUM-4 Derive missing standard traits
- Loading branch information
Showing
6 changed files
with
125 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::{is_compatible_with::IsCompatibleWith, ucum_unit::UcumUnit, Term}; | ||
|
||
/// `Term`s are `PartialOrd` if | ||
/// | ||
/// a) they are compatible | ||
/// b) their `scalar()` values are comparable | ||
/// | ||
/// ```rust | ||
/// use std::cmp::Ordering; | ||
/// use wise_units::{Atom, Prefix, Term}; | ||
/// | ||
/// let lhs = Term { | ||
/// factor: Some(1000), | ||
/// prefix: None, | ||
/// atom: Some(Atom::Meter), | ||
/// exponent: None, | ||
/// annotation: None | ||
/// }; | ||
/// let rhs = Term { | ||
/// factor: None, | ||
/// prefix: Some(Prefix::Kilo), | ||
/// atom: Some(Atom::Meter), | ||
/// exponent: None, | ||
/// annotation: None | ||
/// }; | ||
/// assert_eq!(lhs.partial_cmp(&rhs), Some(Ordering::Equal)); | ||
/// | ||
/// let lhs = Term { | ||
/// factor: None, | ||
/// prefix: None, | ||
/// atom: Some(Atom::Meter), | ||
/// exponent: None, | ||
/// annotation: None | ||
/// }; | ||
/// let rhs = Term { | ||
/// factor: None, | ||
/// prefix: Some(Prefix::Kilo), | ||
/// atom: Some(Atom::Meter), | ||
/// exponent: None, | ||
/// annotation: None | ||
/// }; | ||
/// assert_eq!(lhs.partial_cmp(&rhs), Some(Ordering::Less)); | ||
/// | ||
/// let lhs = Term { | ||
/// factor: None, | ||
/// prefix: None, | ||
/// atom: Some(Atom::Meter), | ||
/// exponent: None, | ||
/// annotation: None | ||
/// }; | ||
/// let rhs = Term { | ||
/// factor: None, | ||
/// prefix: None, | ||
/// atom: Some(Atom::Gram), | ||
/// exponent: None, | ||
/// annotation: None | ||
/// }; | ||
/// assert_eq!(lhs.partial_cmp(&rhs), None); | ||
/// ``` | ||
/// | ||
impl PartialOrd for Term { | ||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { | ||
if !self.is_compatible_with(other) { | ||
return None; | ||
} | ||
|
||
self.scalar().partial_cmp(&other.scalar()) | ||
} | ||
} |