stop requiring annoying reference-based RangeBounds supertrait
This commit is contained in:
@@ -21,7 +21,6 @@ use std::cmp::Ordering;
|
|||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
||||||
use std::iter::once;
|
use std::iter::once;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::RangeBounds;
|
|
||||||
|
|
||||||
use btree_monstrousity::btree_map::{
|
use btree_monstrousity::btree_map::{
|
||||||
IntoIter as BTreeMapIntoIter, SearchBoundCustom,
|
IntoIter as BTreeMapIntoIter, SearchBoundCustom,
|
||||||
@@ -1408,10 +1407,17 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A range that has **Inclusive** end-points.
|
/// A range that has **Inclusive** end-points.
|
||||||
pub trait InclusiveRange<I>: RangeBounds<I> {
|
pub trait InclusiveRange<I> {
|
||||||
fn start(&self) -> I;
|
fn start(&self) -> I;
|
||||||
fn end(&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
|
///requires that self comes before other and they don't overlap
|
||||||
fn touches_ordered(&self, other: &Self) -> bool
|
fn touches_ordered(&self, other: &Self) -> bool
|
||||||
where
|
where
|
||||||
@@ -1425,7 +1431,7 @@ pub trait InclusiveRange<I>: RangeBounds<I> {
|
|||||||
where
|
where
|
||||||
I: DiscreteFinite + Ord,
|
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
|
///requires that self comes before other
|
||||||
|
|||||||
+1
-17
@@ -47,6 +47,7 @@ along with discrete_range_map. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use std::ops::{Bound, RangeBounds};
|
//! use std::ops::{Bound, RangeBounds};
|
||||||
|
//!
|
||||||
//! use discrete_range_map::test_ranges::ie;
|
//! use discrete_range_map::test_ranges::ie;
|
||||||
//! use discrete_range_map::{
|
//! use discrete_range_map::{
|
||||||
//! DiscreteFinite, DiscreteRangeMap, InclusiveInterval,
|
//! DiscreteFinite, DiscreteRangeMap, InclusiveInterval,
|
||||||
@@ -61,23 +62,6 @@ along with discrete_range_map. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
//! Infinite(i8),
|
//! Infinite(i8),
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! // First, we need to implement RangeBounds since its a super-trait
|
|
||||||
//! // of InclusiveRange
|
|
||||||
//! impl RangeBounds<i8> 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
|
//! // First, we need to implement InclusiveRange
|
||||||
//! impl InclusiveRange<i8> for Reservation {
|
//! impl InclusiveRange<i8> for Reservation {
|
||||||
//! fn start(&self) -> i8 {
|
//! fn start(&self) -> i8 {
|
||||||
|
|||||||
Reference in New Issue
Block a user