From 89c968e197860fbebc25c759fe96701295dac309 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Sun, 13 Jun 2021 14:33:14 -0700 Subject: [PATCH] interval: Update for 2nd edition. --- interval/Cargo.toml | 1 + interval/src/lib.rs | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/interval/Cargo.toml b/interval/Cargo.toml index e554b6d..e09417b 100644 --- a/interval/Cargo.toml +++ b/interval/Cargo.toml @@ -2,5 +2,6 @@ name = "interval" version = "0.1.0" authors = ["You "] +edition = "2018" [dependencies] diff --git a/interval/src/lib.rs b/interval/src/lib.rs index 2a122e9..b6b6875 100644 --- a/interval/src/lib.rs +++ b/interval/src/lib.rs @@ -1,17 +1,25 @@ +#![warn(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] + #[derive(Debug, PartialEq)] struct Interval { lower: T, // inclusive - upper: T // exclusive + upper: T, // exclusive } use std::cmp::{Ordering, PartialOrd}; impl PartialOrd> for Interval { fn partial_cmp(&self, other: &Interval) -> Option { - 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 + } } }