|
|
|
@ -1,17 +1,25 @@
|
|
|
|
|
#![warn(rust_2018_idioms)]
|
|
|
|
|
#![allow(elided_lifetimes_in_paths)]
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
|
struct Interval<T> {
|
|
|
|
|
lower: T, // inclusive
|
|
|
|
|
upper: T // exclusive
|
|
|
|
|
upper: T, // exclusive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
use std::cmp::{Ordering, PartialOrd};
|
|
|
|
|
|
|
|
|
|
impl<T: PartialOrd> PartialOrd<Interval<T>> for Interval<T> {
|
|
|
|
|
fn partial_cmp(&self, other: &Interval<T>) -> Option<Ordering> {
|
|
|
|
|
if self == other { Some(Ordering::Equal) }
|
|
|
|
|
else if self.lower >= other.upper { Some(Ordering::Greater) }
|
|
|
|
|
else if self.upper <= other.lower { Some(Ordering::Less) }
|
|
|
|
|
else { None }
|
|
|
|
|
if self == other {
|
|
|
|
|
Some(Ordering::Equal)
|
|
|
|
|
} else if self.lower >= other.upper {
|
|
|
|
|
Some(Ordering::Greater)
|
|
|
|
|
} else if self.upper <= other.lower {
|
|
|
|
|
Some(Ordering::Less)
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|