diff options
| author | Max Verevkin <maxxverrr@gmail.com> | 2022-04-03 22:52:12 +0300 |
|---|---|---|
| committer | Max Verevkin <maxxverrr@gmail.com> | 2022-04-03 22:52:26 +0300 |
| commit | 41b54360ff917a261d3f6f752e3c2c51edada773 (patch) | |
| tree | 2a7beaea62e7da5cdaef29ab5d26db126131c2ea /src/ord_adaptor.rs | |
| parent | 6ab71396f028f6945d2e7554b65c64de146d7e87 (diff) | |
| download | i3bar-mango-41b54360ff917a261d3f6f752e3c2c51edada773.tar.gz | |
small refactoring
Diffstat (limited to 'src/ord_adaptor.rs')
| -rw-r--r-- | src/ord_adaptor.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/ord_adaptor.rs b/src/ord_adaptor.rs new file mode 100644 index 0000000..c7c6763 --- /dev/null +++ b/src/ord_adaptor.rs @@ -0,0 +1,18 @@ +//! Newtypes to use floating numbers in sorting algs + +use std::cmp::Ordering; + +/// Defaults to `Ordering::Less` if the wrapped value can't be compared +#[derive(PartialEq, PartialOrd)] +#[repr(transparent)] +pub struct DefaultLess<T: PartialOrd>(pub T); + +// Not ideal, but `Ord` requires `Eq`, so... +impl<T: PartialOrd> Eq for DefaultLess<T> {} + +#[allow(clippy::derive_ord_xor_partial_ord)] +impl<T: PartialOrd> Ord for DefaultLess<T> { + fn cmp(&self, other: &Self) -> Ordering { + self.partial_cmp(other).unwrap_or(Ordering::Less) + } +} |
