From c579d079939b5d4ee3127579de732f037e612c28 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 6 Jan 2017 15:48:23 -0800 Subject: Remove need for range_contains feature --- src/index.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/index.rs') diff --git a/src/index.rs b/src/index.rs index b1f6f452..daec02f7 100644 --- a/src/index.rs +++ b/src/index.rs @@ -17,7 +17,7 @@ /// Indexing types and implementations for Grid and Line use std::cmp::{Ord, Ordering}; use std::fmt; -use std::ops::{self, Deref, Add, Range}; +use std::ops::{self, Deref, Add, Range, RangeInclusive}; /// The side of a cell #[derive(Debug, Copy, Clone, Eq, PartialEq)] @@ -210,6 +210,29 @@ impl From> for IndexRange { } } +// can be removed if range_contains is stabilized + +pub trait Contains { + type Content; + fn contains_(&self, item: Self::Content) -> bool; +} + +impl> Contains for Range { + type Content = T; + fn contains_(&self, item: Self::Content) -> bool { + (self.start <= item) && (item < self.end) + } +} + +impl> Contains for RangeInclusive { + type Content = T; + fn contains_(&self, item: Self::Content) -> bool { + if let &RangeInclusive::NonEmpty{ref start, ref end} = self { + (*start <= item) && (item <= *end) + } else { false } + } +} + macro_rules! ops { ($ty:ty, $construct:expr) => { add!($ty, $construct); -- cgit v1.2.3-54-g00ecf