diff options
Diffstat (limited to 'src/utils/gen_util.rs')
-rw-r--r-- | src/utils/gen_util.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/utils/gen_util.rs b/src/utils/gen_util.rs index 73c04371..04417dab 100644 --- a/src/utils/gen_util.rs +++ b/src/utils/gen_util.rs @@ -59,3 +59,29 @@ pub fn get_simple_byte_values(bytes: u64, spacing: bool) -> (f64, String) { _ => (bytes as f64 / 1_000_000_000_000.0, "TB".to_string()), } } + +/// Gotta get partial ordering? No problem, here's something to deal with it~ +pub fn get_ordering<T: std::cmp::PartialOrd>( + a_val: T, b_val: T, reverse_order: bool, +) -> std::cmp::Ordering { + match a_val.partial_cmp(&b_val) { + Some(x) => match x { + Ordering::Greater => { + if reverse_order { + std::cmp::Ordering::Less + } else { + std::cmp::Ordering::Greater + } + } + Ordering::Less => { + if reverse_order { + std::cmp::Ordering::Greater + } else { + std::cmp::Ordering::Less + } + } + Ordering::Equal => Ordering::Equal, + }, + None => Ordering::Equal, + } +} |