# [−][src]Struct normalize_interval::interval::Interval

`pub struct Interval<T>(_);`

A contiguous interval of the type T.

`Interval`s are `Normalize`d when created. For `Finite` types, open bounds will be converted to the nearest contained closed bound.

## Implementations

### `impl<T> Interval<T> where    T: Ord + Clone,    RawInterval<T>: Normalize, `[src]

#### `pub fn new(left: Bound<T>, right: Bound<T>) -> Self`[src]

Constructs a new `Interval` from the given `Bound`s.

# 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());```

#### `pub fn empty() -> Self`[src]

Constructs an empty `Interval`.

# Example

`let interval: Interval<i32> = Interval::empty();`

#### `pub fn point(point: T) -> Self`[src]

Constructs a new degenerate `Interval` containing the given point.

# Example

`let interval: Interval<i32> = Interval::point(3);`

#### `pub fn open(left: T, right: T) -> Self`[src]

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());```

#### `pub fn left_open(left: T, right: T) -> Self`[src]

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));```

#### `pub fn right_open(left: T, right: T) -> Self`[src]

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));```

#### `pub fn closed(left: T, right: T) -> Self`[src]

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));```

#### `pub fn left_closed(left: T, right: T) -> Self`[src]

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));```

#### `pub fn right_closed(left: T, right: T) -> Self`[src]

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));```

#### `pub fn unbounded_from(point: T) -> Self`[src]

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)));```

#### `pub fn unbounded_to(point: T) -> Self`[src]

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)));```

#### `pub fn unbounded_up_from(point: T) -> Self`[src]

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)));```

#### `pub fn unbounded_up_to(point: T) -> Self`[src]

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)));```

#### `pub fn full() -> Self`[src]

Constructs a new unbounded `Interval` containing all points.

# Examples

`let interval: Interval<i32> = Interval::full();`

`Finite` types will have their bounds closed:

```let interval: Interval<i32> = Interval::full();

assert_eq!(interval, Interval::new(Include(i32::MIN), Include(i32::MAX)));```

#### `pub fn into_non_empty(self) -> Option<Self>`[src]

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);```

#### `pub fn lower_bound(&self) -> Option<Bound<T>>`[src]

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)));```

#### `pub fn upper_bound(&self) -> Option<Bound<T>>`[src]

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)));```

#### `pub fn infimum(&self) -> Option<T>`[src]

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));```

#### `pub fn supremum(&self) -> Option<T>`[src]

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));```

#### `pub fn size(&self) -> Option<T> where    T: Sub<Output = T>, `[src]

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));```

#### `pub fn is_empty(&self) -> bool`[src]

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);```

#### `pub fn is_degenerate(&self) -> bool`[src]

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);```

#### `pub fn is_proper(&self) -> bool`[src]

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);```

#### `pub fn is_open(&self) -> bool`[src]

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);```

#### `pub fn is_left_open(&self) -> bool`[src]

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);```

#### `pub fn is_right_open(&self) -> bool`[src]

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);```

#### `pub fn is_half_open(&self) -> bool`[src]

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);```

#### `pub fn is_closed(&self) -> bool`[src]

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);```

#### `pub fn is_left_closed(&self) -> bool`[src]

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);```

#### `pub fn is_right_closed(&self) -> bool`[src]

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);```

#### `pub fn is_half_closed(&self) -> bool`[src]

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);```

#### `pub fn is_bounded(&self) -> bool`[src]

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);```

#### `pub fn is_left_bounded(&self) -> bool`[src]

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);```

#### `pub fn is_right_bounded(&self) -> bool`[src]

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);```

#### `pub fn is_half_bounded(&self) -> bool`[src]

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);```

#### `pub fn contains(&self, point: &T) -> bool`[src]

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);```

#### `pub fn intersects(&self, other: &Self) -> bool`[src]

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);```

#### `pub fn adjacent(&self, other: &Self) -> bool`[src]

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);

let a: Interval<i32> = Interval::closed(-3, 5);
let b: Interval<i32> = Interval::closed(8, 12);

#### `pub fn complement(&self) -> impl Iterator<Item = Self>`[src]

Returns `Interval`s containing all points not contained in the `Interval`.

# Example

```let interval: Interval<i32> = Interval::open(-3, 5);

assert_eq!(interval.complement().collect::<Vec<_>>(),
[Interval::unbounded_to(-3), Interval::unbounded_from(5)]);```

#### `pub fn intersect(&self, other: &Self) -> Self`[src]

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));```

#### `pub fn union(&self, other: &Self) -> impl Iterator<Item = Self>`[src]

Returns the `Interval`s 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)]);```

#### `pub fn minus(&self, other: &Self) -> impl Iterator<Item = Self>`[src]

Returns the `Interval`s 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)]);```

#### `pub fn enclose(&self, other: &Self) -> Self`[src]

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));```

#### `pub fn closure(&self) -> Self`[src]

Returns the smallest closed `Interval` containing all of the points in this `Interval`.

# Example

```let interval: Interval<i32> = Interval::open(-3, 7);
assert_eq!(interval.closure(), Interval::closed(-2, 6));```

### `impl<T> Interval<T> where    T: Ord + Clone + Finite, `[src]

#### `pub fn iter(&self) -> Iter<T>ⓘImportant traits for Iter<T>impl<T> Iterator for Iter<T> where    T: Ord + Clone + Finite,  type Item = T;`[src]

Returns an `Iterator` over the points in the `Interval`. Only defined for `Finite` `Interval`s.

# 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

### `impl<T> IntoIterator for Interval<T> where    T: Ord + Clone + Finite, `[src]

#### `type Item = T`

The type of the elements being iterated over.

#### `type IntoIter = Iter<T>`

Which kind of iterator are we turning this into?

## Blanket Implementations

### `impl<I> IntoIterator for I where    I: Iterator, `[src]

#### `type Item = <I as Iterator>::Item`

The type of the elements being iterated over.

#### `type IntoIter = I`

Which kind of iterator are we turning this into?

### `impl<T> ToOwned for T where    T: Clone, `[src]

#### `type Owned = T`

The resulting type after obtaining ownership.

### `impl<T, U> TryFrom<U> for T where    U: Into<T>, `[src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

### `impl<T, U> TryInto<U> for T where    U: TryFrom<T>, `[src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.