From 354815809b9d927e7ade0c77f1a6346f7539beca Mon Sep 17 00:00:00 2001 From: ripytide Date: Sun, 18 Jun 2023 10:49:54 +0100 Subject: [PATCH] stop requiring annoying reference-based RangeBounds supertrait --- src/discrete_range_map.rs | 12 +++++++++--- src/lib.rs | 18 +----------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/discrete_range_map.rs b/src/discrete_range_map.rs index 89a7ff2..1330972 100644 --- a/src/discrete_range_map.rs +++ b/src/discrete_range_map.rs @@ -21,7 +21,6 @@ use std::cmp::Ordering; use std::fmt::{self, Debug}; use std::iter::once; use std::marker::PhantomData; -use std::ops::RangeBounds; use btree_monstrousity::btree_map::{ IntoIter as BTreeMapIntoIter, SearchBoundCustom, @@ -1408,10 +1407,17 @@ where } /// A range that has **Inclusive** end-points. -pub trait InclusiveRange: RangeBounds { +pub trait InclusiveRange { fn start(&self) -> I; fn end(&self) -> I; + fn contains(&self, point: I) -> bool + where + I: Ord, + { + point >= self.start() && point <= self.end() + } + ///requires that self comes before other and they don't overlap fn touches_ordered(&self, other: &Self) -> bool where @@ -1425,7 +1431,7 @@ pub trait InclusiveRange: RangeBounds { where I: DiscreteFinite + Ord, { - self.contains(&other.start()) || self.contains(&other.end()) + self.contains(other.start()) || self.contains(other.end()) } ///requires that self comes before other diff --git a/src/lib.rs b/src/lib.rs index 4abf85d..05097f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,6 +47,7 @@ along with discrete_range_map. If not, see . //! //! ```rust //! use std::ops::{Bound, RangeBounds}; +//! //! use discrete_range_map::test_ranges::ie; //! use discrete_range_map::{ //! DiscreteFinite, DiscreteRangeMap, InclusiveInterval, @@ -61,23 +62,6 @@ along with discrete_range_map. If not, see . //! Infinite(i8), //! } //! -//! // First, we need to implement RangeBounds since its a super-trait -//! // of InclusiveRange -//! impl RangeBounds for Reservation { -//! fn start_bound(&self) -> Bound<&i8> { -//! match self { -//! Reservation::Finite(start, _) => Bound::Included(start), -//! Reservation::Infinite(start) => Bound::Included(start), -//! } -//! } -//! fn end_bound(&self) -> Bound<&i8> { -//! match self { -//! Reservation::Finite(_, end) => Bound::Included(end), -//! Reservation::Infinite(_) => Bound::Included(&i8::MAX), -//! } -//! } -//! } -//! //! // First, we need to implement InclusiveRange //! impl InclusiveRange for Reservation { //! fn start(&self) -> i8 {