[][src]Struct ranges::GenericRange

pub struct GenericRange<T> { /* fields omitted */ }

A generic analog to core/std ranges.

Because this type allows more range types, it comes with the cost of a few guarantees that need to be uphold.

First of all, start is always less than or equal to end. Secondly, both bounds are in the Domain that is implemented for T. In case the constructor encounters a value outside of the domain, the value is clamped to the full domain range.

Note

The notation of (-inf and +inf) is used as an equivalent to the domain minimum and maximum, even if the implementing domain may not be unbound or excluding in either direction.

Implementations

impl<T: PartialOrd> GenericRange<T>[src]

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

Returns true if the given item is contained in the range.

Example

 use ranges::GenericRange;

 let range = GenericRange::from(1..=5);
 assert!(range.contains(&3));

impl<T: Domain> GenericRange<T>[src]

pub fn difference(self, other: Self) -> OperationResult<T>[src]

Returns the difference of two ranges.

Examples

 use ranges::{GenericRange, OperationResult};

 let range = GenericRange::from(1..=5);
 let range2 = range;
 assert_eq!(range - range2, OperationResult::Empty);
 use ranges::{GenericRange, OperationResult};

 let range = GenericRange::from(1..=5);
 let range2 = 1..3;
 assert_eq!(range - range2, OperationResult::Single((3..=5).into()));
 use ranges::{GenericRange, OperationResult};

 let range = GenericRange::from(1..=10);
 let range2 = 3..5;
 assert_eq!(range - range2, OperationResult::Double((1..3).into(), (5..=10).into()));

impl<T: Domain> GenericRange<T>[src]

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

Returns true if the range is empty.

Examples

use ranges::GenericRange;

assert!(GenericRange::from(1..1).is_empty());
assert!(!GenericRange::from(1..=1).is_empty());
assert!(!GenericRange::from(1..2).is_empty());

impl<T: Domain> GenericRange<T>[src]

pub fn intersect(self, other: Self) -> OperationResult<T>[src]

Results in either a single or, if the inputs are disjoint, empty range.

Note

The OperationResult::Double discriminant can safely be marked unreachable!() when matching the output of this method.

Examples

use ranges::{GenericRange, OperationResult};

let range = GenericRange::new_less_than(5);
let range2 = GenericRange::new_at_least(10);

assert_eq!(range & range2, OperationResult::Empty);
use ranges::{GenericRange, OperationResult};

let range = GenericRange::from(0..10);
let range2 = 5..=15;

assert_eq!(range & range2, OperationResult::Single(GenericRange::from(5..10)));

impl<T> GenericRange<T>[src]

#[must_use]pub fn invert_border(bound: Bound<T>) -> Bound<T>[src]

Inverts a range border, so a start becomes an end and vice versa.

Example

use core::ops::Bound;
use ranges::GenericRange;

assert_eq!(GenericRange::invert_border(Bound::<usize>::Unbounded), Bound::Unbounded);
assert_eq!(GenericRange::invert_border(Bound::Excluded(42)), Bound::Included(42));
assert_eq!(GenericRange::invert_border(Bound::Included(42)), Bound::Excluded(42));

#[must_use]pub fn invert_border_cloned(bound: &Bound<T>) -> Bound<T> where
    T: Clone
[src]

Inverts a range border, so a start becomes an end and vice versa. Explicitly clones the contents.

pub fn invert(self) -> OperationResult<T> where
    T: Domain
[src]

Inverts the given range and returns two if no bound is unbounded.

Example

use ranges::{GenericRange, OperationResult};

assert_eq!(!GenericRange::<usize>::full(), OperationResult::Empty);
assert_eq!(
    !GenericRange::new_at_most(5),
    OperationResult::Single(GenericRange::new_greater_than(5))
);
assert_eq!(
    !GenericRange::new_at_least(42),
    OperationResult::Single(GenericRange::new_less_than(42))
);
assert_eq!(
    !GenericRange::from(5..42),
    OperationResult::Double(GenericRange::new_less_than(5), GenericRange::new_at_least(42))
)

impl<T> GenericRange<T>[src]

This is the "core" of this library. Everything basically relies on this one way or another.

Note

If you need to know only one of the possible outcomes it is generally better to use is_*() methods instead of matching on arrangement() or worse relation(). The more specific methods are, as one would expect, only using the bare minimum of information to figure out if the requested arrangement is the case. If, however, a broad knowledge about or even computation with two ranges is required, arrangement() and relation() are the way to go.

#[must_use]pub fn cmp_start_start(start: Bound<&T>, other_start: Bound<&T>) -> Ordering where
    T: Domain
[src]

Compares a start bound with another.

Note

Because the generic Bound enum is used, it is not verified if the two bounds are actually starts. This responsibility rests on the caller.

#[must_use]pub fn cmp_start_end(start: Bound<&T>, end: Bound<&T>) -> Ordering where
    T: Domain
[src]

Compares a start bound with an end bound.

Note

Because the generic Bound enum is used, it is not verified if the two bounds are actually start and end. This responsibility rests on the caller.

#[must_use]pub fn cmp_end_start(end: Bound<&T>, start: Bound<&T>) -> Ordering where
    T: Domain
[src]

Compares an end bound with a start bound.

Note

Because the generic Bound enum is used, it is not verified if the two bounds are actually end and start. This responsibility rests on the caller.

#[must_use]pub fn cmp_end_end(end: Bound<&T>, other_end: Bound<&T>) -> Ordering where
    T: Domain
[src]

Compares an end bound with another.

Note

Because the generic Bound enum is used, it is not verified if the two bounds are actually ends. This responsibility rests on the caller.

#[must_use]pub fn is_bound_touching(bound: Bound<&T>, other: Bound<&T>) -> bool where
    T: PartialEq
[src]

Returns true if two bounds are touching.

#[must_use]pub fn is_disjoint(&self, other: &Self) -> bool where
    T: Domain
[src]

Returns true if two ranges are disjoint.

Note

No information regarding their arrangement is obtained or returned. Please refer to GenericRange::arrangement() or GenericRange::relation() and match the result on their respective Disjoint discriminant.

#[must_use]pub fn is_touching(&self, other: &Self) -> bool where
    T: PartialEq + Domain
[src]

Returns true if two ranges are touching.

Note

No information regarding their arrangement is obtained or returned. Please refer to GenericRange::arrangement() or GenericRange::relation() and match the result on their respective Touching discriminant.

#[must_use]pub fn is_overlapping(&self, other: &Self) -> bool where
    T: Domain
[src]

Returns true if two ranges are overlapping.

Note

No information regarding their arrangement is obtained or returned. Please refer to GenericRange::arrangement() or GenericRange::relation() and match the result on their respective Overlapping discriminant.

#[must_use]pub fn is_containing(&self, other: &Self) -> bool where
    T: Domain
[src]

Returns true if self contains other.

Note

This method and is_contained_by() are the only two that differentiate by arrangement. If knowledge about containment (in either orientation) is the only information you need, it is still generally faster to call these two instead of using GenericRange::arrangement() or GenericRange::relation().

#[must_use]pub fn is_contained_by(&self, other: &Self) -> bool where
    T: Domain
[src]

Returns true if self is contained in other.

Note

This method and is_containing() are the only two that differentiate by arrangement. If knowledge about containment (in either orientation) is the only information you need, it is still generally faster to call these two instead of using GenericRange::arrangement() or GenericRange::relation().

#[must_use]pub fn is_starting_with(&self, other: &Self) -> bool where
    T: Domain
[src]

Returns true if two ranges are starting on the same element.

Note

No information regarding their arrangement is obtained or returned. Please refer to GenericRange::arrangement() or GenericRange::relation() and match the result on their respective Starting discriminant.

#[must_use]pub fn is_ending_with(&self, other: &Self) -> bool where
    T: Domain
[src]

Returns true if two ranges are ending on the same element.

Note

No information regarding their arrangement is obtained or returned. Please refer to GenericRange::arrangement() or GenericRange::relation() and match the result on their respective Ending discriminant.

#[must_use]pub fn is_equal(&self, other: &Self) -> bool where
    T: Domain
[src]

Returns true if the two ranges are equal.

This method is the basis for the PartialEq and Eq trait implementations.

Note

For discrete types, this may have counter-intuitive results. See examples.

Examples

use ranges::GenericRange;

assert_eq!(GenericRange::from(1..3), (1..=2).into());
assert_eq!(GenericRange::new_open_closed(1, 3), (2..=3).into());
assert_eq!(GenericRange::new_open(0, 5), (1..=4).into());

#[must_use]pub fn relation(self, other: Self) -> Relation<T> where
    T: Clone + Domain
[src]

Compares this GenericRange<T> with another one. The relation is expressed as an enum containing only the arrangement in form of the discriminant and some additionally obtained information about the original inputs and, if applicable, either one is less, shorter, or a singleton.

In addition to the same data obtained by GenericRange::arrangement(), the original ranges are moved into the struct to allow direct processing.

#[must_use]pub fn arrangement(&self, other: &Self) -> Arrangement where
    T: Domain
[src]

Compares this GenericRange<T> with another one. The relation is expressed as an enum containing only the arrangement in form of the discriminant and some additionally obtained information about the original inputs and, if applicable, either one is less, shorter, or a singleton.

impl<T: Domain> GenericRange<T>[src]

#[must_use]pub fn singleton(value: T) -> Self where
    T: Clone
[src]

Constructs a singleton by cloning the input storing it in included bounds for both start and end.

Example

use core::ops::Bound;
use ranges::GenericRange;

assert_eq!(
    GenericRange::singleton(42),
    (Bound::Included(42), Bound::Included(42)).into()
);

#[must_use]pub fn is_singleton(&self) -> bool[src]

Returns true if the range only contains a single item.

Examples

use core::ops::Bound;
use ranges::GenericRange;

assert!(!GenericRange::from(1..1).is_singleton());
assert!(GenericRange::from(1..2).is_singleton());

assert!(GenericRange::from(1..=1).is_singleton());
assert!(!GenericRange::from(1..=2).is_singleton());

assert!(GenericRange::from((Bound::Excluded(1), Bound::Included(2))).is_singleton());

impl<T: Domain> GenericRange<T>[src]

pub fn symmetric_difference(self, other: Self) -> OperationResult<T>[src]

Results in two ranges if the inputs are disjoint or touching. Results in two ranges (the "left" and "right" disjoint parts) if the inputs are overlapping or contain one another. Results in a single range (the disjoint part) if the inputs start or end on the same value. Returns empty if the inputs are equal.

Examples

Disjoint ranges.

use ranges::{GenericRange, OperationResult};

let a = GenericRange::new_less_than(5);
let b = GenericRange::new_at_least(10);

assert_eq!(a ^ b, OperationResult::Double(a, b));

Ranges start with the same element.

use ranges::{GenericRange, OperationResult};

let a = GenericRange::from(0..10);
let b = 0..=8;

assert_eq!(a ^ b, OperationResult::Single(GenericRange::new_open(8, 10)));

Equal ranges.

use ranges::{GenericRange, OperationResult};

let a = GenericRange::from(5..=10);
let b = a; // this works because Copy is implemented for i32.

assert_eq!(a ^ b, OperationResult::Empty);

impl<T: Domain> GenericRange<T>[src]

pub fn union(self, other: Self) -> OperationResult<T>[src]

Results in either a single or, if the inputs are disjoint, two ranges.

Examples

Disjoint ranges.

use ranges::{GenericRange, OperationResult};

let range = GenericRange::new_less_than(5);
let range2 = GenericRange::new_at_least(10);

assert_eq!(range | range2, OperationResult::Double(range, range2));

Overlapping ranges.

use ranges::{GenericRange, OperationResult};

let range = GenericRange::from(0..10);
let range2 = 5..=15;

assert_eq!(range | range2, OperationResult::Single((0..=15).into()));

impl<T: Domain> GenericRange<T>[src]

Constructors and relevant comparison methods.

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

Creates a new GenericRange using the domain minimum and maximum as start and end.

core/std equivalent

RangeFull or ...

Interval notation

(-inf, +inf)

#[must_use]pub fn is_full(&self) -> bool[src]

Returns true if the start is the domain minimum and the end is the domain maximum.

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

Returns true if the range start is open/excluded.

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

Returns true if the range start is closed/included.

#[must_use]pub fn is_left_unbounded(&self) -> bool[src]

Returns true if the range start is unbounded.

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

Returns true if the range end is open/excluded.

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

Returns true if the range end is closed/included.

#[must_use]pub fn is_right_unbounded(&self) -> bool[src]

Returns true if the range end is unbounded.

#[must_use]pub fn new_greater_than(start: T) -> Self[src]

Convenience method calling new_left_open_right_unbounded.

#[must_use]pub fn new_left_open_right_unbounded(start: T) -> Self[src]

Creates a new GenericRange with an open/excluded start and an unbound end. Convenience method equivalent is new_greater_than.

core/std equivalent

There is no equivalent because open/excluded starts are not representable.

Interval notation

(start, +inf)

#[must_use]pub fn is_left_open_right_unbounded(&self) -> bool[src]

Returns true if the range start is open/excluded and the end is unbounded.

#[must_use]pub fn new_at_least(start: T) -> Self[src]

Convenience method calling new_left_closed_right_unbounded.

#[must_use]pub fn new_left_closed_right_unbounded(start: T) -> Self[src]

Creates a new GenericRange with a closed/included start and an unbound end. Convenience method equivalent is new_at_least.

core/std equivalent

RangeFrom or start...

Interval notation

[start, +inf)

#[must_use]pub fn is_left_closed_right_unbounded(&self) -> bool[src]

Returns true if the range start is closed/included and the end is unbounded.

#[must_use]pub fn new_less_than(end: T) -> Self[src]

Convenience method calling new_left_unbounded_right_open.

#[must_use]pub fn new_left_unbounded_right_open(end: T) -> Self[src]

Creates a new GenericRange with an unbounded start and an open/excluded end. Convenience method equivalent is new_less_than.

core/std equivalent

RangeTo or ..end.

Interval notation

(-inf, end)

#[must_use]pub fn is_left_unbounded_right_open(&self) -> bool[src]

Returns true if the range start is unbounded and the end is open/excluded.

#[must_use]pub fn new_at_most(end: T) -> Self[src]

Convenience method calling new_left_unbounded_right_closed.

#[must_use]pub fn new_left_unbounded_right_closed(end: T) -> Self[src]

Creates a new GenericRange with an unbounded start and a closed/included end. Convenience method equivalent is new_at_most.

core/std equivalent

RangeToInclusive or ..=end.

Interval notation

(-inf, end]

#[must_use]pub fn is_left_unbounded_right_closed(&self) -> bool[src]

Returns true if the range start is unbounded and the end is closed/included.

#[must_use]pub fn new_open(start: T, end: T) -> Self[src]

Convenience method calling new_left_open_right_open.

#[must_use]pub fn new_left_open_right_open(start: T, end: T) -> Self[src]

Creates a new GenericRange with an open/excluded start and end. Convenience method equivalent is new_open.

core/std equivalent

There is no equivalent because open/excluded starts are not representable.

Interval notation

(start, end)

#[must_use]pub fn is_left_open_right_open(&self) -> bool[src]

Returns true if the range start and end are open/excluded.

#[must_use]pub fn new_closed(start: T, end: T) -> Self[src]

Convenience method calling new_left_closed_right_closed.

#[must_use]pub fn new_left_closed_right_closed(start: T, end: T) -> Self[src]

Creates a new GenericRange with a closed/included start and end. Convenience method equivalent is new_closed.

core/std equivalent

RangeInclusive or start..=end.

Interval notation

[start, end]

#[must_use]pub fn is_left_closed_right_closed(&self) -> bool[src]

Returns true if the range start and end are closed/included.

#[must_use]pub fn new_closed_open(start: T, end: T) -> Self[src]

Convenience method calling new_left_closed_right_open.

#[must_use]pub fn new_left_closed_right_open(start: T, end: T) -> Self[src]

Creates a new GenericRange with a closed/included start and an open/excluded end. Convenience method equivalent is new_closed_open.

core/std equivalent

Range or start..end.

Interval notation

[start, end)

#[must_use]pub fn is_left_closed_right_open(&self) -> bool[src]

Returns true if the range start is closed/included and the end is open/excluded.

#[must_use]pub fn new_open_closed(start: T, end: T) -> Self[src]

Convenience method calling new_left_open_right_closed.

#[must_use]pub fn new_left_open_right_closed(start: T, end: T) -> Self[src]

Creates a new GenericRange with a closed/included start and an open/excluded end. Convenience method equivalent is new_open_closed.

core/std equivalent

There is no equivalent because open/excluded starts are not representable.

Interval notation

(start, end]

#[must_use]pub fn is_left_open_right_closed(&self) -> bool[src]

Returns true if the range start is open/excluded and the end is closed/included.

#[must_use]pub fn new_with_bounds(start: Bound<T>, end: Bound<T>) -> Self[src]

Custom range from Bounds.

Panics

It is asserted that start <= end.

Trait Implementations

impl<T: Binary + Domain> Binary for GenericRange<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

use ranges::GenericRange;

assert_eq!(format!("{}", GenericRange::from(1..2)), "{1}");
assert_eq!(format!("{}", GenericRange::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", GenericRange::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", GenericRange::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", GenericRange::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", GenericRange::from(42..=100)), "[42,100]");

impl<T, I> BitAnd<I> for GenericRange<T> where
    I: Into<GenericRange<T>>,
    T: Domain
[src]

type Output = OperationResult<T>

The resulting type after applying the & operator.

impl<T, I> BitOr<I> for GenericRange<T> where
    I: Into<GenericRange<T>>,
    T: Domain
[src]

This calls self.union(other).

type Output = OperationResult<T>

The resulting type after applying the | operator.

impl<T, I> BitXor<I> for GenericRange<T> where
    I: Into<GenericRange<T>>,
    T: Domain
[src]

type Output = OperationResult<T>

The resulting type after applying the ^ operator.

impl<T: Clone> Clone for GenericRange<T>[src]

impl<T: Copy> Copy for GenericRange<T>[src]

impl<T: Debug> Debug for GenericRange<T>[src]

impl<T: Display + Domain> Display for GenericRange<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

use ranges::GenericRange;

assert_eq!(format!("{}", GenericRange::from(1..2)), "{1}");
assert_eq!(format!("{}", GenericRange::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", GenericRange::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", GenericRange::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", GenericRange::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", GenericRange::from(42..=100)), "[42,100]");

impl<T: Domain> Eq for GenericRange<T>[src]

impl<T: Domain> From<(Bound<T>, Bound<T>)> for GenericRange<T>[src]

Converts the tuple using Self::with_bounds(tuple.0, tuple.1).

impl<T: Domain> From<Range<T>> for GenericRange<T>[src]

impl<T: Domain> From<RangeFrom<T>> for GenericRange<T>[src]

Converts the RangeFrom using Self::at_least(range.start).

impl<T: Domain> From<RangeFull> for GenericRange<T>[src]

Converts the RangeFull using Self::full().

impl<T: Domain> From<RangeInclusive<T>> for GenericRange<T>[src]

Converts the RangeInclusive using Self::closed(start, end).

impl<T: Domain> From<RangeTo<T>> for GenericRange<T>[src]

Converts the RangeTo using Self::less_than(range.end).

impl<T: Domain> From<RangeToInclusive<T>> for GenericRange<T>[src]

Converts the RangeToInclusive using Self::at_most(range.end).

impl<T: Domain + Clone> From<T> for GenericRange<T>[src]

impl<T: Domain> FromIterator<GenericRange<T>> for Ranges<T>[src]

impl<T: Domain + Hash> Hash for GenericRange<T>[src]

impl<T> IntoIterator for GenericRange<T> where
    T: Iterable<Output = T>, 
[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = GenericIterator<T>

Which kind of iterator are we turning this into?

pub fn into_iter(self) -> Self::IntoIter[src]

Panics

This function panics when trying to convert a range with an unbound start, as there is no way to determine where to start iterating at. However, if the domain of T has a minimum, calling this is safe, as it was set as the start when the range was constructed.

impl<T: LowerExp + Domain> LowerExp for GenericRange<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

use ranges::GenericRange;

assert_eq!(format!("{}", GenericRange::from(1..2)), "{1}");
assert_eq!(format!("{}", GenericRange::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", GenericRange::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", GenericRange::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", GenericRange::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", GenericRange::from(42..=100)), "[42,100]");

impl<T: LowerHex + Domain> LowerHex for GenericRange<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

use ranges::GenericRange;

assert_eq!(format!("{}", GenericRange::from(1..2)), "{1}");
assert_eq!(format!("{}", GenericRange::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", GenericRange::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", GenericRange::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", GenericRange::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", GenericRange::from(42..=100)), "[42,100]");

impl<T: Domain> Not for GenericRange<T>[src]

This calls self.invert().

type Output = OperationResult<T>

The resulting type after applying the ! operator.

impl<T: Octal + Domain> Octal for GenericRange<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

use ranges::GenericRange;

assert_eq!(format!("{}", GenericRange::from(1..2)), "{1}");
assert_eq!(format!("{}", GenericRange::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", GenericRange::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", GenericRange::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", GenericRange::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", GenericRange::from(42..=100)), "[42,100]");

impl<T: Domain> PartialEq<GenericRange<T>> for GenericRange<T>[src]

impl<T: Pointer + Domain> Pointer for GenericRange<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

use ranges::GenericRange;

assert_eq!(format!("{}", GenericRange::from(1..2)), "{1}");
assert_eq!(format!("{}", GenericRange::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", GenericRange::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", GenericRange::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", GenericRange::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", GenericRange::from(42..=100)), "[42,100]");

impl<T> RangeBounds<T> for GenericRange<T>[src]

impl<T, I> Sub<I> for GenericRange<T> where
    I: Into<GenericRange<T>>,
    T: Domain
[src]

type Output = OperationResult<T>

The resulting type after applying the - operator.

impl<T: UpperExp + Domain> UpperExp for GenericRange<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

use ranges::GenericRange;

assert_eq!(format!("{}", GenericRange::from(1..2)), "{1}");
assert_eq!(format!("{}", GenericRange::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", GenericRange::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", GenericRange::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", GenericRange::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", GenericRange::from(42..=100)), "[42,100]");

impl<T: UpperHex + Domain> UpperHex for GenericRange<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

use ranges::GenericRange;

assert_eq!(format!("{}", GenericRange::from(1..2)), "{1}");
assert_eq!(format!("{}", GenericRange::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", GenericRange::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", GenericRange::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", GenericRange::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", GenericRange::from(42..=100)), "[42,100]");

Auto Trait Implementations

impl<T> Send for GenericRange<T> where
    T: Send
[src]

impl<T> Sync for GenericRange<T> where
    T: Sync
[src]

impl<T> Unpin for GenericRange<T> where
    T: Unpin
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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.