Struct normalize_interval::interval::Interval
source · pub struct Interval<T>(/* private fields */);Expand description
Implementations§
source§impl<T> Interval<T>
impl<T> Interval<T>
sourcepub fn new(left: Bound<T>, right: Bound<T>) -> Self
pub fn new(left: Bound<T>, right: Bound<T>) -> Self
Constructs a new Interval from the given Bounds.
§Examples
let interval: Interval<i32> = Interval::new(Include(3), Exclude(7));Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::new(Exclude(-3), Exclude(7));
assert_eq!(interval, Interval::new(Include(-2), Include(6)));If the bounds are out of order, and empty Interval will be returned.
let interval: Interval<i32> = Interval::new(Exclude(7), Exclude(-7));
assert_eq!(interval, Interval::empty());sourcepub fn point(point: T) -> Self
pub fn point(point: T) -> Self
Constructs a new degenerate Interval containing the given point.
§Example
let interval: Interval<i32> = Interval::point(3);sourcepub fn open(left: T, right: T) -> Self
pub fn open(left: T, right: T) -> Self
Constructs a new bounded open Interval from the given points.
§Examples
let interval: Interval<i32> = Interval::open(3, 7);Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::open(-3, 7);
assert_eq!(interval, Interval::new(Include(-2), Include(6)));If the bounds are out of order, and empty Interval will be returned.
let interval: Interval<i32> = Interval::open(7, -7);
assert_eq!(interval, Interval::empty());sourcepub fn left_open(left: T, right: T) -> Self
pub fn left_open(left: T, right: T) -> Self
Constructs a new bounded left-open Interval from the given points.
§Examples
let interval: Interval<i32> = Interval::left_open(3, 7);Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::left_open(-3, 7);
assert_eq!(interval, Interval::new(Include(-2), Include(7)));If the bounds are out of order, and empty Interval will be returned.
let interval: Interval<i32> = Interval::left_open(7, -7);
assert_eq!(interval, Interval::empty());If the bounds are identical, a point Interval will be returned.
let interval: Interval<i32> = Interval::left_open(5, 5);
assert_eq!(interval, Interval::point(5));sourcepub fn right_open(left: T, right: T) -> Self
pub fn right_open(left: T, right: T) -> Self
Constructs a new bounded right-open Interval from the given points.
§Examples
let interval: Interval<i32> = Interval::right_open(3, 7);Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::right_open(-3, 7);
assert_eq!(interval, Interval::new(Include(-3), Include(6)));If the bounds are out of order, and empty Interval will be returned.
let interval: Interval<i32> = Interval::right_open(7, -7);
assert_eq!(interval, Interval::empty());If the bounds are identical, a point Interval will be returned.
let interval: Interval<i32> = Interval::right_open(5, 5);
assert_eq!(interval, Interval::point(5));sourcepub fn closed(left: T, right: T) -> Self
pub fn closed(left: T, right: T) -> Self
Constructs a new bounded closed Interval from the given points.
§Examples
let interval: Interval<i32> = Interval::closed(3, 7);If the bounds are out of order, and empty Interval will be returned.
let interval: Interval<i32> = Interval::closed(7, -7);
assert_eq!(interval, Interval::empty());If the bounds are identical, a point Interval will be returned.
let interval: Interval<i32> = Interval::closed(5, 5);
assert_eq!(interval, Interval::point(5));sourcepub fn left_closed(left: T, right: T) -> Self
pub fn left_closed(left: T, right: T) -> Self
Constructs a new bounded left-closed Interval from the given points.
§Examples
let interval: Interval<i32> = Interval::left_closed(3, 7);Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::left_closed(-3, 7);
assert_eq!(interval, Interval::new(Include(-3), Include(6)));If the bounds are out of order, and empty Interval will be returned.
let interval: Interval<i32> = Interval::left_closed(7, -7);
assert_eq!(interval, Interval::empty());If the bounds are identical, a point Interval will be returned.
let interval: Interval<i32> = Interval::left_closed(5, 5);
assert_eq!(interval, Interval::point(5));sourcepub fn right_closed(left: T, right: T) -> Self
pub fn right_closed(left: T, right: T) -> Self
Constructs a new bounded right-closed Interval from the given points.
§Examples
let interval: Interval<i32> = Interval::right_closed(3, 7);Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::right_closed(-3, 7);
assert_eq!(interval, Interval::new(Include(-2), Include(7)));If the bounds are out of order, and empty Interval will be returned.
let interval: Interval<i32> = Interval::right_closed(7, -7);
assert_eq!(interval, Interval::empty());If the bounds are identical, a point Interval will be returned.
let interval: Interval<i32> = Interval::right_closed(5, 5);
assert_eq!(interval, Interval::point(5));sourcepub fn unbounded_from(point: T) -> Self
pub fn unbounded_from(point: T) -> Self
Constructs a new right-unbounded Interval from (and including) the
given point.
§Examples
let interval: Interval<i32> = Interval::unbounded_from(3);Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::unbounded_from(7);
assert_eq!(interval, Interval::new(Include(7), Include(i32::MAX)));sourcepub fn unbounded_to(point: T) -> Self
pub fn unbounded_to(point: T) -> Self
Constructs a new left-unbounded Interval to (and including) the
given point.
§Examples
let interval: Interval<i32> = Interval::unbounded_to(3);Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::unbounded_to(7);
assert_eq!(interval, Interval::new(Include(i32::MIN), Include(7)));sourcepub fn unbounded_up_from(point: T) -> Self
pub fn unbounded_up_from(point: T) -> Self
Constructs a new right-unbounded Interval from (but excluding) the
given point.
§Examples
let interval: Interval<i32> = Interval::unbounded_up_from(3);Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::unbounded_up_from(7);
assert_eq!(interval, Interval::new(Include(8), Include(i32::MAX)));sourcepub fn unbounded_up_to(point: T) -> Self
pub fn unbounded_up_to(point: T) -> Self
Constructs a new left-unbounded Interval to (but excluding) the
given point.
§Examples
let interval: Interval<i32> = Interval::unbounded_up_to(3);Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::unbounded_up_to(7);
assert_eq!(interval, Interval::new(Include(i32::MIN), Include(6)));sourcepub fn into_non_empty(self) -> Option<Self>
pub fn into_non_empty(self) -> Option<Self>
Converts the Interval into an Option, returning None if it is
empty.
let interval: Interval<i32> = Interval::closed(0, 4);
assert_eq!(interval.into_non_empty(), Some(Interval::closed(0, 4)));
let interval: Interval<i32> = Interval::empty();
assert_eq!(interval.into_non_empty(), None);sourcepub fn lower_bound(&self) -> Option<Bound<T>>
pub fn lower_bound(&self) -> Option<Bound<T>>
Returns the lower Bound of the Interval, or None if the
Interval is empty.
§Examples
let interval: Interval<i32> = Interval::closed(-3, 5);
assert_eq!(interval.lower_bound(), Some(Include(-3)));Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::open(-3, 5);
assert_eq!(interval.lower_bound(), Some(Include(-2)));sourcepub fn upper_bound(&self) -> Option<Bound<T>>
pub fn upper_bound(&self) -> Option<Bound<T>>
Returns the upper Bound of the Interval, or None if the
Interval is empty.
§Examples
let interval: Interval<i32> = Interval::closed(-3, 5);
assert_eq!(interval.upper_bound(), Some(Include(5)));Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::open(-3, 5);
assert_eq!(interval.upper_bound(), Some(Include(4)));sourcepub fn infimum(&self) -> Option<T>
pub fn infimum(&self) -> Option<T>
Returns the greatest lower bound of the Interval, or None if the
Interval is empty or unbounded below.
§Examples
let interval: Interval<i32> = Interval::closed(-3, 5);
assert_eq!(interval.infimum(), Some(-3));Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::open(-3, 5);
assert_eq!(interval.infimum(), Some(-2));sourcepub fn supremum(&self) -> Option<T>
pub fn supremum(&self) -> Option<T>
Returns the least upper bound of the Interval, or None if the
Interval is empty or unbounded above.
§Examples
let interval: Interval<i32> = Interval::closed(-3, 5);
assert_eq!(interval.supremum(), Some(5));Finite types will have their bounds closed:
let interval: Interval<i32> = Interval::open(-3, 5);
assert_eq!(interval.supremum(), Some(4));sourcepub fn size(&self) -> Option<T>where
T: Sub<Output = T>,
pub fn size(&self) -> Option<T>where
T: Sub<Output = T>,
Returns the size of the Interval, or None if it is either infinite
or empty.
§Example
let interval: Interval<i32> = Interval::closed(-3, 7);
assert_eq!(interval.size(), Some(10));sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the interval contains no points.
§Example
let interval: Interval<i32> = Interval::closed(-3, 5);
assert_eq!(interval.is_empty(), false);
let interval: Interval<i32> = Interval::empty();
assert_eq!(interval.is_empty(), true);sourcepub fn is_degenerate(&self) -> bool
pub fn is_degenerate(&self) -> bool
Returns true if the interval contains a single point.
§Example
let interval: Interval<i32> = Interval::closed(-3, 5);
assert_eq!(interval.is_degenerate(), false);
let interval: Interval<i32> = Interval::point(4);
assert_eq!(interval.is_degenerate(), true);sourcepub fn is_proper(&self) -> bool
pub fn is_proper(&self) -> bool
Returns true if the interval contains more than one point.
§Example
let interval: Interval<i32> = Interval::closed(-3, 5);
assert_eq!(interval.is_proper(), true);
let interval: Interval<i32> = Interval::point(4);
assert_eq!(interval.is_proper(), false);
let interval: Interval<i32> = Interval::empty();
assert_eq!(interval.is_proper(), false);sourcepub fn is_open(&self) -> bool
pub fn is_open(&self) -> bool
Returns true if the interval is open.
§Examples
let interval: Interval<i32> = Interval::left_open(-3, 5);
assert_eq!(interval.is_open(), false);
let interval: Interval<i32> = Interval::point(4);
assert_eq!(interval.is_open(), false);Note that the empty and full intervals are open:
let interval: Interval<i32> = Interval::empty();
assert_eq!(interval.is_open(), true);
let interval: Interval<i32> = Interval::full();
assert_eq!(interval.is_open(), false);sourcepub fn is_left_open(&self) -> bool
pub fn is_left_open(&self) -> bool
Returns true if the interval is left-open.
§Examples
let interval: Interval<i32> = Interval::left_open(-3, 5);
assert_eq!(interval.is_left_open(), false);
let interval: Interval<i32> = Interval::closed(2, 4);
assert_eq!(interval.is_left_open(), false);Note that the left-unbounded intervals are considered left-open:
let interval: Interval<i32> = Interval::unbounded_to(4);
assert_eq!(interval.is_left_open(), false);
let interval: Interval<i32> = Interval::full();
assert_eq!(interval.is_left_open(), false);sourcepub fn is_right_open(&self) -> bool
pub fn is_right_open(&self) -> bool
Returns true if the interval is right-open.
§Examples
let interval: Interval<i32> = Interval::right_open(-3, 5);
assert_eq!(interval.is_right_open(), false);
let interval: Interval<i32> = Interval::closed(2, 4);
assert_eq!(interval.is_right_open(), false);Note that the right-unbounded intervals are considered right-open:
let interval: Interval<i32> = Interval::unbounded_from(4);
assert_eq!(interval.is_right_open(), false);
let interval: Interval<i32> = Interval::full();
assert_eq!(interval.is_right_open(), false);sourcepub fn is_half_open(&self) -> bool
pub fn is_half_open(&self) -> bool
Returns true if the interval is half-open.
§Examples
let interval: Interval<i32> = Interval::left_open(-3, 5);
assert_eq!(interval.is_half_open(), false);
let interval: Interval<i32> = Interval::closed(2, 4);
assert_eq!(interval.is_half_open(), false);Note that the half-unbounded intervals are considered half-open:
let interval: Interval<i32> = Interval::unbounded_to(4);
assert_eq!(interval.is_half_open(), false);
let interval: Interval<i32> = Interval::full();
assert_eq!(interval.is_half_open(), false);sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Returns true if the interval is closed.
§Examples
let interval: Interval<i32> = Interval::closed(-3, 5);
assert_eq!(interval.is_closed(), true);
let interval: Interval<i32> = Interval::left_open(-2, 4);
assert_eq!(interval.is_closed(), true);Note that the empty and full intervals are closed:
let interval: Interval<i32> = Interval::empty();
assert_eq!(interval.is_closed(), true);
let interval: Interval<i32> = Interval::full();
assert_eq!(interval.is_closed(), true);sourcepub fn is_left_closed(&self) -> bool
pub fn is_left_closed(&self) -> bool
Returns true if the interval is left-closed.
§Example
let interval: Interval<i32> = Interval::closed(-3, 5);
assert_eq!(interval.is_left_closed(), true);
let interval: Interval<i32> = Interval::left_open(-2, 4);
assert_eq!(interval.is_left_closed(), true);sourcepub fn is_right_closed(&self) -> bool
pub fn is_right_closed(&self) -> bool
Returns true if the interval is right-closed.
§Example
let interval: Interval<i32> = Interval::closed(-3, 5);
assert_eq!(interval.is_right_closed(), true);
let interval: Interval<i32> = Interval::right_open(-2, 4);
assert_eq!(interval.is_right_closed(), true);sourcepub fn is_half_closed(&self) -> bool
pub fn is_half_closed(&self) -> bool
Returns true if the interval is half-closed.
§Example
let interval: Interval<i32> = Interval::unbounded_to(-3);
assert_eq!(interval.is_half_closed(), false);
let interval: Interval<i32> = Interval::open(-2, 4);
assert_eq!(interval.is_half_closed(), false);sourcepub fn is_bounded(&self) -> bool
pub fn is_bounded(&self) -> bool
Returns true if the the interval is bounded.
§Example
let interval: Interval<i32> = Interval::open(-2, 4);
assert_eq!(interval.is_left_bounded(), true);
let interval: Interval<i32> = Interval::unbounded_to(-3);
assert_eq!(interval.is_left_bounded(), true);sourcepub fn is_left_bounded(&self) -> bool
pub fn is_left_bounded(&self) -> bool
Returns true if the the interval is left-bounded.
§Example
let interval: Interval<i32> = Interval::open(-2, 4);
assert_eq!(interval.is_left_bounded(), true);
let interval: Interval<i32> = Interval::unbounded_to(-3);
assert_eq!(interval.is_left_bounded(), true);sourcepub fn is_right_bounded(&self) -> bool
pub fn is_right_bounded(&self) -> bool
Returns true if the the interval is right-bounded.
§Example
let interval: Interval<i32> = Interval::open(-2, 4);
assert_eq!(interval.is_right_bounded(), true);
let interval: Interval<i32> = Interval::unbounded_from(-3);
assert_eq!(interval.is_right_bounded(), true);sourcepub fn is_half_bounded(&self) -> bool
pub fn is_half_bounded(&self) -> bool
Returns true if the the interval is helf-bounded.
§Example
let interval: Interval<i32> = Interval::unbounded_to(-2);
assert_eq!(interval.is_half_bounded(), false);
let interval: Interval<i32> = Interval::full();
assert_eq!(interval.is_half_bounded(), false);sourcepub fn contains(&self, point: &T) -> bool
pub fn contains(&self, point: &T) -> bool
Returns true if the the interval contains the given point.
§Example
let interval: Interval<i32> = Interval::closed(0, 20);
assert_eq!(interval.contains(&2), true);
assert_eq!(interval.contains(&-15), false);sourcepub fn intersects(&self, other: &Self) -> bool
pub fn intersects(&self, other: &Self) -> bool
Returns true if the Interval overlaps the given Interval.
§Example
let a: Interval<i32> = Interval::closed(-3, 5);
let b: Interval<i32> = Interval::closed(4, 15);
assert_eq!(a.intersects(&b), true);
let a: Interval<i32> = Interval::closed(-3, 5);
let b: Interval<i32> = Interval::closed(8, 12);
assert_eq!(a.intersects(&b), false);sourcepub fn is_adjacent_to(&self, other: &Self) -> bool
pub fn is_adjacent_to(&self, other: &Self) -> bool
Returns true if the Interval shares a bound with the given
Interval.
§Example
let a: Interval<i32> = Interval::closed(-3, 5);
let b: Interval<i32> = Interval::closed(5, 15);
assert_eq!(a .is_adjacent_to(&b), true);
let a: Interval<i32> = Interval::closed(-3, 5);
let b: Interval<i32> = Interval::closed(8, 12);
assert_eq!(a .is_adjacent_to(&b), false);sourcepub fn complement(&self) -> impl Iterator<Item = Self>
pub fn complement(&self) -> impl Iterator<Item = Self>
sourcepub fn intersect(&self, other: &Self) -> Self
pub fn intersect(&self, other: &Self) -> Self
Returns the largest Interval whose points are all contained entirely
within the Interval and the given Interval.
§Example
let a: Interval<i32> = Interval::closed(-3, 7);
let b: Interval<i32> = Interval::closed(4, 13);
assert_eq!(a.intersect(&b), Interval::closed(4, 7));sourcepub fn union(&self, other: &Self) -> impl Iterator<Item = Self>
pub fn union(&self, other: &Self) -> impl Iterator<Item = Self>
Returns the Intervals containing all points in the Interval and the
given Interval.
§Example
let a: Interval<i32> = Interval::closed(-3, 7);
let b: Interval<i32> = Interval::closed(4, 13);
assert_eq!(a.union(&b).collect::<Vec<_>>(),
[Interval::closed(-3, 13)]);sourcepub fn minus(&self, other: &Self) -> impl Iterator<Item = Self>
pub fn minus(&self, other: &Self) -> impl Iterator<Item = Self>
Returns the Intervals containing all points in the Interval which
are not in the given Interval.
§Example
let a: Interval<i32> = Interval::closed(-3, 7);
let b: Interval<i32> = Interval::closed(4, 13);
assert_eq!(a.minus(&b).collect::<Vec<_>>(),
[Interval::right_open(-3, 4)]);sourcepub fn enclose(&self, other: &Self) -> Self
pub fn enclose(&self, other: &Self) -> Self
Returns the smallest Interval that contains all of the points
contained within the Interval and the given Interval.
§Example
let a: Interval<i32> = Interval::closed(-3, 5);
let b: Interval<i32> = Interval::closed(9, 13);
assert_eq!(a.enclose(&b), Interval::closed(-3, 13));source§impl<T> Interval<T>
impl<T> Interval<T>
sourcepub fn iter(&self) -> Iter<T> ⓘ
pub fn iter(&self) -> Iter<T> ⓘ
Returns an Iterator over the points in the Interval. Only defined
for Finite Intervals.
§Examples
let interval: Interval<i32> = Interval::open(3, 7);
assert_eq!(interval.iter().collect::<Vec<_>>(), [4, 5, 6]);The Interval can be iterated in both directions.
let interval: Interval<i32> = Interval::open(3, 7);
assert_eq!(interval.iter().rev().collect::<Vec<_>>(), [6, 5, 4]);Trait Implementations§
source§impl<T> Extend<Interval<T>> for Selection<T>
impl<T> Extend<Interval<T>> for Selection<T>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Interval<T>>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Interval<T>>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)source§impl<T> From<RangeToInclusive<T>> for Interval<T>
impl<T> From<RangeToInclusive<T>> for Interval<T>
source§fn from(r: RangeToInclusive<T>) -> Self
fn from(r: RangeToInclusive<T>) -> Self
source§impl<T> From<RawInterval<T>> for Interval<T>
impl<T> From<RawInterval<T>> for Interval<T>
source§fn from(raw_interval: RawInterval<T>) -> Self
fn from(raw_interval: RawInterval<T>) -> Self
source§impl<T> FromIterator<Interval<T>> for Selection<T>
impl<T> FromIterator<Interval<T>> for Selection<T>
source§impl<'a, T> IntoIterator for &'a Interval<T>
impl<'a, T> IntoIterator for &'a Interval<T>
source§impl<T> IntoIterator for Interval<T>
impl<T> IntoIterator for Interval<T>
impl<T: Copy> Copy for Interval<T>
impl<T: Eq> Eq for Interval<T>
impl<T> StructuralPartialEq for Interval<T>
Auto Trait Implementations§
impl<T> Freeze for Interval<T>where
T: Freeze,
impl<T> RefUnwindSafe for Interval<T>where
T: RefUnwindSafe,
impl<T> Send for Interval<T>where
T: Send,
impl<T> Sync for Interval<T>where
T: Sync,
impl<T> Unpin for Interval<T>where
T: Unpin,
impl<T> UnwindSafe for Interval<T>where
T: UnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)