interval: Update for 2nd edition.

pull/13/head
Jim Blandy 3 years ago
parent 5cf5a6e5bc
commit 89c968e197

@ -2,5 +2,6 @@
name = "interval"
version = "0.1.0"
authors = ["You <you@example.com>"]
edition = "2018"
[dependencies]

@ -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
}
}
}

Loading…
Cancel
Save