pub struct Interval<T, L = Inclusive, R = L> { /* private fields */ }Expand description
Interval like [a, b], (a, b), [a, b), and (a, b] for any PartialOrd type.
T: Numeric type bounding real number line.Tshould implementsPartialOrd.NaNsafety is not guaranteed whenTis floating point type.L: Left boundary type. Specify one ofInclusive,Exclusive, orBoundType.R: Right boundary type. Specify one ofInclusiveExclusive, orBoundType.Interval<T>(=Interval<T, Inclusive, Inclusive>) represents a closed interval, i.e., [a, b].Interval<T, Exclusive>(=Interval<T, Exclusive, Exclusive>) represents a open interval, i.e., (a, b).Interval<T, Inclusive, Exclusive>represents a right half-open interval, i.e., [a, b).Interval<T, Exclusive, Inclusive>represents a left half-open interval, i.e., (a, b].Interval<T, BoundType>represents any of the above.
This type is considered as an interval on ℝ (real number line), even if an integer type is specified for T.
§Memory cost
use inter_val::{Interval, Exclusive, Inclusive, BoundType};
use std::mem::size_of;
// When bound type is statically determined, the size of the interval is just the size of two `T`.
assert_eq!(size_of::<Interval<i32, Inclusive>>(), size_of::<i32>() * 2);
assert_eq!(size_of::<Interval<f64, Exclusive>>(), size_of::<f64>() * 2);
// Size is larger when bound type is not statically determined.
assert!(size_of::<Interval<i32, BoundType>>() >= (size_of::<i32>() + size_of::<BoundType>()) * 2);§Properties
lower_bound left . center right upper_bound
...------------>|<------- self -------------------->|<------------ ...
inf sup
[<------------ closure ------------>]
(<----------- interior ---------->)§Set operations
|<------------- a ----------------->| . p |<-------- c -------->|
|<--------------- b ------------------->|
|<--- a.intersection(&b) --->|
|<-- a.gap(&c) -->|
|<------------- a.hull(p) ------------->|
|<---------------------------------- a.span(&c) --------------------------->|
|<--------------------------------->| + |<------------------->| a.union(&c)
|<---->| a.difference(&b)
|<- δ -+---- c.dilate(δ) ----+- δ ->|Implementations§
Source§impl<T, L, R> Interval<T, L, R>
impl<T, L, R> Interval<T, L, R>
pub fn left(&self) -> &LeftBounded<T, L>
pub fn right(&self) -> &RightBounded<T, R>
Source§impl<T: PartialOrd, L: BoundaryOf<Left>, R: BoundaryOf<Right>> Interval<T, L, R>
impl<T: PartialOrd, L: BoundaryOf<Left>, R: BoundaryOf<Right>> Interval<T, L, R>
Sourcepub fn try_new(left: Bound<T, L>, right: Bound<T, R>) -> Option<Self>
pub fn try_new(left: Bound<T, L>, right: Bound<T, R>) -> Option<Self>
Try to create a new interval. Return None if the interval is empty.
use std::any::{Any, TypeId};
use inter_val::{Interval, BoundType, Exclusive, Inclusive};
let a: Interval<i32, Inclusive, Exclusive> = Interval::try_new(0.into(), 3.into()).unwrap();
assert!(a.contains(&0));
assert!(a.contains(&2));
assert!(!a.contains(&3));
let a = Interval::try_new(Exclusive.at(0), Inclusive.at(3)).unwrap();
assert_eq!(a.type_id(), TypeId::of::<Interval<i32, Exclusive, Inclusive>>());
let a = Interval::try_new(BoundType::Exclusive.at(0), BoundType::Exclusive.at(3)).unwrap();
assert_eq!(a.type_id(), TypeId::of::<Interval<i32, BoundType, BoundType>>());
assert!(Interval::try_new(Inclusive.at(3), Exclusive.at(0)).is_none()); // [3, 0) is empty.
assert!(Interval::try_new(Inclusive.at(3), Exclusive.at(3)).is_none()); // [3, 3) is empty.
assert!(Interval::try_new(Inclusive.at(3), Inclusive.at(3)).is_some()); // [3, 3] is not empty.
assert!(Interval::try_new(Exclusive.at(0), Exclusive.at(1)).is_some()); // (0, 1) is not empty.Sourcepub fn new(left: Bound<T, L>, right: Bound<T, R>) -> Self
pub fn new(left: Bound<T, L>, right: Bound<T, R>) -> Self
Create a new interval. Panics if the interval is empty.
use std::any::{Any, TypeId};
use inter_val::{Interval, BoundType, Exclusive, Inclusive};
let a: Interval<i32, Inclusive, Exclusive> = Interval::new(0.into(), 3.into());
assert!(a.contains(&0));
assert!(a.contains(&2));
assert!(!a.contains(&3));
let a = Interval::new(Exclusive.at(0), Inclusive.at(3));
assert_eq!(a.type_id(), TypeId::of::<Interval<i32, Exclusive, Inclusive>>());
let a = Interval::new(BoundType::Exclusive.at(0), BoundType::Exclusive.at(3));
assert_eq!(a.type_id(), TypeId::of::<Interval<i32, BoundType, BoundType>>());§Panics
ⓘ
Interval::new(Inclusive.at(3), Exclusive.at(0)); // [3, 0) is empty.ⓘ
Interval::new(Inclusive.at(3), Exclusive.at(3)); // [3, 3) is empty.Sourcepub fn try_between(a: T, b: T) -> Option<Self>
pub fn try_between(a: T, b: T) -> Option<Self>
use inter_val::{Interval, Exclusive, Inclusive};
let a: Interval<i32, Inclusive, Exclusive> = Interval::try_between(-2, 5).unwrap();
assert_eq!(a, Inclusive.at(-2).to(Exclusive.at(5)));
let a: Interval<i32, Inclusive, Exclusive> = Interval::try_between(3, -1).unwrap();
assert_eq!(a, Inclusive.at(-1).to(Exclusive.at(3))); // Swaps left and right.
assert!(Interval::<i32, Inclusive, Exclusive>::try_between(1, 1).is_none()); // [1, 1) is empty.
assert!(Interval::<i32, Inclusive, Inclusive>::try_between(1, 1).is_some()); // [1, 1] is not empty.Sourcepub fn between(a: T, b: T) -> Self
pub fn between(a: T, b: T) -> Self
use inter_val::{Interval, Exclusive, Inclusive};
let a: Interval<i32, Inclusive, Exclusive> = Interval::between(-2, 5);
assert_eq!(a, Inclusive.at(-2).to(Exclusive.at(5)));
let a: Interval<i32, Inclusive, Exclusive> = Interval::between(3, -1);
assert_eq!(a, Inclusive.at(-1).to(Exclusive.at(3))); // Swaps left and right.
// Closed interval (bounded by `Inclusive`) never panics.
Interval::<i32, Inclusive, Inclusive>::between(1, 1); // Doesn't panic since [1, 1] is not empty.ⓘ
Interval::<i32, Inclusive, Exclusive>::between(1, 1); // Panics since [1, 1) is empty.Sourcepub fn inf(&self) -> &T
pub fn inf(&self) -> &T
Shorthand of .left().limit
use inter_val::{Interval, Exclusive, Inclusive};
let a = Interval::new(Exclusive.at(-1.0), Inclusive.at(1.0));
assert_eq!(a.inf(), &-1.0);
assert_eq!(a.inf(), &a.left().limit);
assert!(!a.contains(&-1.0));Sourcepub fn sup(&self) -> &T
pub fn sup(&self) -> &T
Shorthand of .right().limit
use inter_val::{Interval, Exclusive, Inclusive};
let a = Interval::new(Inclusive.at(-1.0), Exclusive.at(1.0));
assert_eq!(a.sup(), &1.0);
assert_eq!(a.sup(), &a.right().limit);
assert!(!a.contains(&1.0));pub fn closure(self) -> Interval<T, Inclusive>
pub fn interior(self) -> Option<Interval<T, Exclusive>>
Sourcepub fn contains(&self, t: &T) -> bool
pub fn contains(&self, t: &T) -> bool
use inter_val::{Interval, Inclusive, Exclusive};
let a = Inclusive.at(4).to(Exclusive.at(7));
let b = Exclusive.at(1.23).to(Inclusive.at(4.56));
assert!(a.contains(&4));
assert!(!a.contains(&7));
assert!(!b.contains(&1.23));
assert!(b.contains(&1.230000000001));
assert!(b.contains(&4.56));Sourcepub fn dilate(self, delta: T) -> Self
pub fn dilate(self, delta: T) -> Self
use inter_val::{Inclusive, Exclusive};
let a = Inclusive.at(4).to(Exclusive.at(7)); // [4, 7)
assert_eq!(a.dilate(2), Inclusive.at(2).to(Exclusive.at(9))); // [4-2, 7+2) = [2, 9)
assert_eq!(a.dilate(-1), Inclusive.at(5).to(Exclusive.at(6))); // [4+1, 7-1) = [5, 6)ⓘ
use inter_val::{Inclusive, Exclusive};
let a = Inclusive.at(4).to(Exclusive.at(7)); // [4, 7)
a.dilate(-2); // panic! [4+2, 7-2) = [6, 5) is empty.Sourcepub fn includes(&self, other: &Self) -> bool
pub fn includes(&self, other: &Self) -> bool
use inter_val::{Interval, Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3));
let b = Inclusive.at(0).to(Exclusive.at(4));
let c = Inclusive.at(1).to(Exclusive.at(4));
assert!(a.includes(&a));
assert!(!a.includes(&b) && b.includes(&a));
assert!(!a.includes(&c) && !c.includes(&a));Sourcepub fn overlaps(&self, other: &Self) -> bool
pub fn overlaps(&self, other: &Self) -> bool
use inter_val::{Interval, Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3));
let b = Inclusive.at(1).to(Exclusive.at(4));
let c = Inclusive.at(3).to(Exclusive.at(5));
assert!(a.overlaps(&a));
assert!(a.overlaps(&b) && b.overlaps(&a));
assert!(!a.overlaps(&c) && !c.overlaps(&a));Sourcepub fn intersection(&self, other: &Self) -> Option<Self>where
T: Clone,
pub fn intersection(&self, other: &Self) -> Option<Self>where
T: Clone,
use inter_val::{Interval, Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3));
let b = Inclusive.at(1).to(Exclusive.at(4));
let c = Inclusive.at(3).to(Exclusive.at(5));
assert_eq!(a.intersection(&a), Some(a));
assert_eq!(a.intersection(&b), Some(Inclusive.at(1).to(Exclusive.at(3))));
assert_eq!(a.intersection(&c), None);Sourcepub fn span(&self, other: &Self) -> Selfwhere
T: Clone,
pub fn span(&self, other: &Self) -> Selfwhere
T: Clone,
use inter_val::{Interval, Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3));
let b = Inclusive.at(5).to(Exclusive.at(8));
assert_eq!(a.span(&b), Inclusive.at(0).to(Exclusive.at(8)));Sourcepub fn hull(self, t: T) -> Selfwhere
T: Clone,
pub fn hull(self, t: T) -> Selfwhere
T: Clone,
use inter_val::{Interval, Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3));
assert_eq!(a.hull(-2), Inclusive.at(-2).to(Exclusive.at(3)));
assert_eq!(a.hull(5), Inclusive.at(0).to(Exclusive.at(5)));Sourcepub fn gap(&self, other: &Self) -> Option<Interval<T, R::Flip, L::Flip>>where
T: Clone,
L::Flip: BoundaryOf<Right>,
R::Flip: BoundaryOf<Left>,
pub fn gap(&self, other: &Self) -> Option<Interval<T, R::Flip, L::Flip>>where
T: Clone,
L::Flip: BoundaryOf<Right>,
R::Flip: BoundaryOf<Left>,
use inter_val::{Interval, Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3));
let b = Inclusive.at(5).to(Exclusive.at(8));
assert_eq!(a.gap(&b).unwrap(), Inclusive.at(3).to(Exclusive.at(5)));Sourcepub fn union(&self, other: &Self) -> IntervalUnion<T, L, R>where
T: Clone,
L::Flip: BoundaryOf<Right>,
R::Flip: BoundaryOf<Left>,
pub fn union(&self, other: &Self) -> IntervalUnion<T, L, R>where
T: Clone,
L::Flip: BoundaryOf<Right>,
R::Flip: BoundaryOf<Left>,
use inter_val::{Interval, Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3));
let b = Inclusive.at(5).to(Exclusive.at(8));
let union = a.union(&b);
assert_eq!(union.span, a.span(&b));
assert_eq!(union.gap, a.gap(&b));
let union_ints: Vec<Interval<_, _, _>> = union.into_iter().collect();
assert_eq!(union_ints.len(), 2);
assert_eq!(union_ints[0], a);
assert_eq!(union_ints[1], b);pub fn lower_bound(&self) -> RightBounded<T, L::Flip>where
T: Clone,
pub fn upper_bound(&self) -> LeftBounded<T, R::Flip>where
T: Clone,
Sourcepub fn measure(&self) -> T
pub fn measure(&self) -> T
use inter_val::{Interval, Inclusive, Exclusive};
let a = Inclusive.at(2.1).to(Inclusive.at(5.3));
assert_eq!(a.measure(), 5.3 - 2.1);
let a = Exclusive.at(0).to(Exclusive.at(1)); // (0, 1)
assert_eq!(a.measure(), 1);Sourcepub fn step_by(&self, step: T) -> impl Iterator<Item = T> + '_
pub fn step_by(&self, step: T) -> impl Iterator<Item = T> + '_
use inter_val::{Inclusive, Exclusive};
let a = Exclusive.at(10).to(Inclusive.at(20)); // (10, 20]
assert!(a.step_by(2).eq(vec![12, 14, 16, 18, 20]));Sourcepub fn step_rev_by(&self, step: T) -> impl Iterator<Item = T> + '_
pub fn step_rev_by(&self, step: T) -> impl Iterator<Item = T> + '_
use inter_val::{Inclusive, Exclusive};
let a = Exclusive.at(10).to(Inclusive.at(20)); // (10, 20]
assert!(a.step_rev_by(2).eq(vec![20, 18, 16, 14, 12]));Sourcepub fn span_many<A: Borrow<Self>>(
items: impl IntoIterator<Item = A>,
) -> Option<Self>where
T: Clone,
pub fn span_many<A: Borrow<Self>>(
items: impl IntoIterator<Item = A>,
) -> Option<Self>where
T: Clone,
use inter_val::{Interval, Inclusive, Exclusive, Nullable};
let a = Inclusive.at(0).to(Exclusive.at(3)); // [0, 3)
let b = Inclusive.at(1).to(Exclusive.at(5)); // [1, 5)
let c = Inclusive.at(8).to(Exclusive.at(10)); // [8, 10)
let span = Interval::span_many(vec![a, b, c]).unwrap(); // [0, 10)
assert_eq!(span.left().limit, 0);
assert_eq!(span.right().limit, 10);
// Sum for Nullable<Interval> can be used as well.
let sum: Nullable<Interval<_, _, _>> = vec![a, b, c].into_iter().sum();
assert_eq!(sum.unwrap(), span);Sourcepub fn hull_many(items: impl IntoIterator<Item = T>) -> Option<Self>
pub fn hull_many(items: impl IntoIterator<Item = T>) -> Option<Self>
use inter_val::{Interval, Nullable};
let hull = Interval::<_>::hull_many(vec![3, 9, 2, 5]).unwrap(); // [2, 9]
assert_eq!(hull.inf(), &2);
assert_eq!(hull.sup(), &9);
let hull = Interval::<_>::hull_many(vec![3.1, 9.2, 2.3, 5.4]).unwrap(); // [2.3, 9.2]
assert_eq!(hull.inf(), &2.3);
assert_eq!(hull.sup(), &9.2);
// Sum for Nullable<Interval> can be used as well.
let a: Nullable<Interval<i32>> = vec![1, 6, 2, 8, 3].into_iter().sum();
assert_eq!(a.unwrap(), Interval::between(1, 8));Source§impl<T: PartialOrd, L: BoundaryOf<Left, Flip = R>, R: BoundaryOf<Right, Flip = L>> Interval<T, L, R>
impl<T: PartialOrd, L: BoundaryOf<Left, Flip = R>, R: BoundaryOf<Right, Flip = L>> Interval<T, L, R>
Sourcepub fn difference(&self, other: &Self) -> IntervalDifference<T, L, R>where
T: Clone,
pub fn difference(&self, other: &Self) -> IntervalDifference<T, L, R>where
T: Clone,
Difference is defined only for Interval<T, Inclusive, Exclusive>, Interval<T, Exclusive, Inclusive>, and Interval<T, BoundType>.
use inter_val::{Interval, Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3));
let b = Inclusive.at(1).to(Exclusive.at(4));
let diff = a.difference(&b);
assert!(diff.lower.is_some() && diff.upper.is_none());
assert_eq!(diff.lower.unwrap(), Inclusive.at(0).to(Exclusive.at(1)));
assert_eq!(diff.into_iter().collect::<Vec<_>>().len(), 1);Source§impl<T: PartialOrd + Clone> Interval<T, Inclusive, Exclusive>
impl<T: PartialOrd + Clone> Interval<T, Inclusive, Exclusive>
Sourcepub fn try_split_at(&self, t: T) -> (Option<Self>, Option<Self>)
pub fn try_split_at(&self, t: T) -> (Option<Self>, Option<Self>)
use inter_val::{Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3)); // [0, 3)
let (b, c) = a.try_split_at(1); // [0, 1) and [1, 3)
assert_eq!(b, Some(Inclusive.at(0).to(Exclusive.at(1))));
assert_eq!(c, Some(Inclusive.at(1).to(Exclusive.at(3))));
let (b, c) = a.try_split_at(0);
assert_eq!(b, None); // [0, 0) is empty.
assert_eq!(c, Some(a)); // [0, 3)Sourcepub fn split_at(&self, t: T) -> (Self, Self)
pub fn split_at(&self, t: T) -> (Self, Self)
use inter_val::{Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3)); // [0, 3)
let (b, c) = a.split_at(1); // [0, 1) and [1, 3)
assert_eq!(b, Inclusive.at(0).to(Exclusive.at(1)));
assert_eq!(c, Inclusive.at(1).to(Exclusive.at(3)));ⓘ
use inter_val::{Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3)); // [0, 3)
let (b, c) = a.split_at(0);Source§impl<T: Float, L: BoundaryOf<Left>, R: BoundaryOf<Right>> Interval<T, L, R>
impl<T: Float, L: BoundaryOf<Left>, R: BoundaryOf<Right>> Interval<T, L, R>
Sourcepub fn center(&self) -> T
pub fn center(&self) -> T
use inter_val::{Interval, Inclusive};
let a = Inclusive.at(2.1).to(Inclusive.at(5.3));
assert_eq!(a.center(), (2.1 + 5.3) / 2.0);Sourcepub fn iou(&self, other: &Self) -> T
pub fn iou(&self, other: &Self) -> T
IoU - Intersection over Union.
use inter_val::{Interval, Inclusive};
let a = Inclusive.at(0.0).to(Inclusive.at(1.0));
let b = Inclusive.at(0.0).to(Inclusive.at(2.0));
let c = Inclusive.at(1.0).to(Inclusive.at(2.0));
assert_eq!(a.iou(&a), 1.0);
assert_eq!(a.iou(&b), 0.5);
assert_eq!(a.iou(&c), 0.0);Sourcepub fn lerp(&self, ratio: T) -> T
pub fn lerp(&self, ratio: T) -> T
Linear interpolation.
use inter_val::{Interval, Inclusive, Exclusive};
let a = Inclusive.at(2.0).to(Inclusive.at(4.0)); // [2, 4]
assert_eq!(a.lerp(0.0), 2.0);
assert_eq!(a.lerp(0.5), 3.0);
assert_eq!(a.lerp(1.0), 4.0);
assert_eq!(a.lerp(1.1), 4.2);Sourcepub fn step_uniform(&self, n: usize) -> impl Iterator<Item = T> + '_
pub fn step_uniform(&self, n: usize) -> impl Iterator<Item = T> + '_
use inter_val::{Interval, Inclusive, Exclusive};
let a = Inclusive.at(2.0).to(Inclusive.at(4.0)); // [2, 4]
let b = Inclusive.at(2.0).to(Exclusive.at(4.0)); // [2, 4)
let c = Exclusive.at(2.0).to(Inclusive.at(4.0)); // (2, 4]
assert!(a.step_uniform(4).eq(vec![2.0, 2.5, 3.0, 3.5, 4.0]));
assert!(b.step_uniform(4).eq(vec![2.0, 2.5, 3.0, 3.5]));
assert!(c.step_uniform(4).eq(vec![2.5, 3.0, 3.5, 4.0]));Source§impl<T: NumCast, L, R> Interval<T, L, R>
impl<T: NumCast, L, R> Interval<T, L, R>
Sourcepub fn try_cast<U: NumCast>(self) -> Option<Interval<U, L, R>>
pub fn try_cast<U: NumCast>(self) -> Option<Interval<U, L, R>>
Cast by num::NumCast.
use inter_val::{Interval, Exclusive};
let src: Interval<f64> = Interval::between(1.2, 7.8); // closed interval [1.2, 7.8]
let dst = src.try_cast::<i32>().unwrap();
assert_eq!(dst.inf(), &1);
assert_eq!(dst.sup(), &7);Trait Implementations§
Source§impl<T> From<Interval<T>> for Interval<T, BoundType>
use inter_val::{BoundType, Inclusive, Interval};
let src: Interval<i32, Inclusive> = Inclusive.at(0).to(Inclusive.at(10));
let dst: Interval<i32, BoundType> = src.into();
assert_eq!(dst.left().bound_type, BoundType::Inclusive);
assert_eq!(dst.right().bound_type, BoundType::Inclusive);
impl<T> From<Interval<T>> for Interval<T, BoundType>
use inter_val::{BoundType, Inclusive, Interval};
let src: Interval<i32, Inclusive> = Inclusive.at(0).to(Inclusive.at(10));
let dst: Interval<i32, BoundType> = src.into();
assert_eq!(dst.left().bound_type, BoundType::Inclusive);
assert_eq!(dst.right().bound_type, BoundType::Inclusive);Source§impl<T> From<Interval<T>> for RangeInclusive<T>
use inter_val::{Interval, Inclusive};
let src = Inclusive.at(0).to(Inclusive.at(10));
let dst: std::ops::RangeInclusive<i32> = src.into();
assert_eq!(dst.start(), &0);
assert_eq!(dst.end(), &10);
impl<T> From<Interval<T>> for RangeInclusive<T>
use inter_val::{Interval, Inclusive};
let src = Inclusive.at(0).to(Inclusive.at(10));
let dst: std::ops::RangeInclusive<i32> = src.into();
assert_eq!(dst.start(), &0);
assert_eq!(dst.end(), &10);Source§impl<T> From<Interval<T, Exclusive>> for Interval<T, BoundType>
use inter_val::{BoundType, Exclusive, Interval};
let src: Interval<i32, Exclusive> = Exclusive.at(0).to(Exclusive.at(10));
let dst: Interval<i32, BoundType> = src.into();
assert_eq!(dst.left().bound_type, BoundType::Exclusive);
assert_eq!(dst.right().bound_type, BoundType::Exclusive);
impl<T> From<Interval<T, Exclusive>> for Interval<T, BoundType>
use inter_val::{BoundType, Exclusive, Interval};
let src: Interval<i32, Exclusive> = Exclusive.at(0).to(Exclusive.at(10));
let dst: Interval<i32, BoundType> = src.into();
assert_eq!(dst.left().bound_type, BoundType::Exclusive);
assert_eq!(dst.right().bound_type, BoundType::Exclusive);Source§impl<T> From<Interval<T, Exclusive, Inclusive>> for Interval<T, BoundType>
use inter_val::{BoundType, Inclusive, Exclusive, Interval};
let src: Interval<i32, Exclusive, Inclusive> = Exclusive.at(0).to(Inclusive.at(10));
let dst: Interval<i32, BoundType> = src.into();
assert_eq!(dst.left().bound_type, BoundType::Exclusive);
assert_eq!(dst.right().bound_type, BoundType::Inclusive);
impl<T> From<Interval<T, Exclusive, Inclusive>> for Interval<T, BoundType>
use inter_val::{BoundType, Inclusive, Exclusive, Interval};
let src: Interval<i32, Exclusive, Inclusive> = Exclusive.at(0).to(Inclusive.at(10));
let dst: Interval<i32, BoundType> = src.into();
assert_eq!(dst.left().bound_type, BoundType::Exclusive);
assert_eq!(dst.right().bound_type, BoundType::Inclusive);Source§impl<T> From<Interval<T, Inclusive, Exclusive>> for Interval<T, BoundType>
use inter_val::{BoundType, Inclusive, Exclusive, Interval};
let src: Interval<i32, Inclusive, Exclusive> = Inclusive.at(0).to(Exclusive.at(10));
let dst: Interval<i32, BoundType> = src.into();
assert_eq!(dst.left().bound_type, BoundType::Inclusive);
assert_eq!(dst.right().bound_type, BoundType::Exclusive);
impl<T> From<Interval<T, Inclusive, Exclusive>> for Interval<T, BoundType>
use inter_val::{BoundType, Inclusive, Exclusive, Interval};
let src: Interval<i32, Inclusive, Exclusive> = Inclusive.at(0).to(Exclusive.at(10));
let dst: Interval<i32, BoundType> = src.into();
assert_eq!(dst.left().bound_type, BoundType::Inclusive);
assert_eq!(dst.right().bound_type, BoundType::Exclusive);Source§impl<T> From<Interval<T, Inclusive, Exclusive>> for Range<T>
use inter_val::{Interval, Inclusive, Exclusive};
let src = Inclusive.at(0).to(Exclusive.at(10));
let dst: std::ops::Range<i32> = src.into();
assert_eq!(dst.start, 0);
assert_eq!(dst.end, 10);
impl<T> From<Interval<T, Inclusive, Exclusive>> for Range<T>
use inter_val::{Interval, Inclusive, Exclusive};
let src = Inclusive.at(0).to(Exclusive.at(10));
let dst: std::ops::Range<i32> = src.into();
assert_eq!(dst.start, 0);
assert_eq!(dst.end, 10);Source§impl<T: PartialOrd + Clone> From<T> for Interval<T, Inclusive>
use std::any::{Any, TypeId};
use inter_val::{Inclusive, Interval};
let a: Interval<_, _, _> = 3.into();
assert_eq!(a.type_id(), TypeId::of::<Interval<i32, Inclusive, Inclusive>>());
assert_eq!(a.left().limit, 3);
assert_eq!(a.right().limit, 3);
impl<T: PartialOrd + Clone> From<T> for Interval<T, Inclusive>
use std::any::{Any, TypeId};
use inter_val::{Inclusive, Interval};
let a: Interval<_, _, _> = 3.into();
assert_eq!(a.type_id(), TypeId::of::<Interval<i32, Inclusive, Inclusive>>());
assert_eq!(a.left().limit, 3);
assert_eq!(a.right().limit, 3);Source§impl<T, L, R> IntoIterator for Interval<T, L, R>
use inter_val::{Interval, Exclusive, Inclusive, BoundType};
// Iterate Interval<i32, Exclusive, Inclusive>
let items: Vec<_> = Exclusive.at(0).to(Inclusive.at(10)).into_iter().collect();
assert_eq!(items.len(), 10);
assert_eq!(items[0], 1);
assert_eq!(items.last().unwrap(), &10);
// Iterate Interval<i32, BoundType, BoundType>
let items: Vec<_> = (BoundType::Exclusive.at(0).to(BoundType::Inclusive.at(10)))
.into_iter()
.collect();
assert_eq!(items.len(), 10);
assert_eq!(items[0], 1);
assert_eq!(items.last().unwrap(), &10);
impl<T, L, R> IntoIterator for Interval<T, L, R>
use inter_val::{Interval, Exclusive, Inclusive, BoundType};
// Iterate Interval<i32, Exclusive, Inclusive>
let items: Vec<_> = Exclusive.at(0).to(Inclusive.at(10)).into_iter().collect();
assert_eq!(items.len(), 10);
assert_eq!(items[0], 1);
assert_eq!(items.last().unwrap(), &10);
// Iterate Interval<i32, BoundType, BoundType>
let items: Vec<_> = (BoundType::Exclusive.at(0).to(BoundType::Inclusive.at(10)))
.into_iter()
.collect();
assert_eq!(items.len(), 10);
assert_eq!(items[0], 1);
assert_eq!(items.last().unwrap(), &10);Source§impl<T, L, R> Sum<Interval<T, L, R>> for Nullable<Interval<T, L, R>>where
T: PartialOrd + Clone,
L: BoundaryOf<Left>,
R: BoundaryOf<Right>,
use inter_val::{Nullable, Interval, Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3)); // [0, 3)
let b = Inclusive.at(1).to(Exclusive.at(5)); // [1, 5)
let c = Inclusive.at(8).to(Exclusive.at(10)); // [8, 10)
let span: Nullable<Interval<_, _, _>> = vec![a, b, c].into_iter().sum(); // [0, 10)
assert_eq!(span.as_ref().unwrap().left().limit, 0);
assert_eq!(span.as_ref().unwrap().right().limit, 10);
impl<T, L, R> Sum<Interval<T, L, R>> for Nullable<Interval<T, L, R>>where
T: PartialOrd + Clone,
L: BoundaryOf<Left>,
R: BoundaryOf<Right>,
use inter_val::{Nullable, Interval, Inclusive, Exclusive};
let a = Inclusive.at(0).to(Exclusive.at(3)); // [0, 3)
let b = Inclusive.at(1).to(Exclusive.at(5)); // [1, 5)
let c = Inclusive.at(8).to(Exclusive.at(10)); // [8, 10)
let span: Nullable<Interval<_, _, _>> = vec![a, b, c].into_iter().sum(); // [0, 10)
assert_eq!(span.as_ref().unwrap().left().limit, 0);
assert_eq!(span.as_ref().unwrap().right().limit, 10);Source§impl<T: PartialOrd> TryFrom<Range<T>> for Interval<T, Inclusive, Exclusive>
use std::any::{Any, TypeId};
use inter_val::{Interval, Inclusive, Exclusive};
let a: Interval<_, _, _> = (2..4).try_into().unwrap();
assert_eq!(a.type_id(), TypeId::of::<Interval<i32, Inclusive, Exclusive>>());
assert_eq!(a.left().limit, 2);
assert_eq!(a.right().limit, 4);
impl<T: PartialOrd> TryFrom<Range<T>> for Interval<T, Inclusive, Exclusive>
use std::any::{Any, TypeId};
use inter_val::{Interval, Inclusive, Exclusive};
let a: Interval<_, _, _> = (2..4).try_into().unwrap();
assert_eq!(a.type_id(), TypeId::of::<Interval<i32, Inclusive, Exclusive>>());
assert_eq!(a.left().limit, 2);
assert_eq!(a.right().limit, 4);Source§impl<T: PartialOrd> TryFrom<RangeInclusive<T>> for Interval<T, Inclusive>
use std::any::{Any, TypeId};
use inter_val::{Interval, Inclusive};
let a: Interval<_, _, _> = (2..=4).try_into().unwrap();
assert_eq!(a.type_id(), TypeId::of::<Interval<i32, Inclusive, Inclusive>>());
assert_eq!(a.left().limit, 2);
assert_eq!(a.right().limit, 4);
impl<T: PartialOrd> TryFrom<RangeInclusive<T>> for Interval<T, Inclusive>
use std::any::{Any, TypeId};
use inter_val::{Interval, Inclusive};
let a: Interval<_, _, _> = (2..=4).try_into().unwrap();
assert_eq!(a.type_id(), TypeId::of::<Interval<i32, Inclusive, Inclusive>>());
assert_eq!(a.left().limit, 2);
assert_eq!(a.right().limit, 4);Source§type Error = IntervalIsEmpty
type Error = IntervalIsEmpty
The type returned in the event of a conversion error.
impl<T: Copy, L: Copy, R: Copy> Copy for Interval<T, L, R>
impl<T: Eq, L: Eq, R: Eq> Eq for Interval<T, L, R>
impl<T, L, R> StructuralPartialEq for Interval<T, L, R>
Auto Trait Implementations§
impl<T, L, R> Freeze for Interval<T, L, R>
impl<T, L, R> RefUnwindSafe for Interval<T, L, R>
impl<T, L, R> Send for Interval<T, L, R>
impl<T, L, R> Sync for Interval<T, L, R>
impl<T, L, R> Unpin for Interval<T, L, R>
impl<T, L, R> UnwindSafe for Interval<T, L, R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more