[−][src]Trait ranges::Domain
Provides otherwise unknown information about the type it is being implemented for.
There are five properties which can be combined into six categories a domain can be in, each with their own implementation requirements and assumptions.
Should the type you're trying to implement not fit into any of these, please open an issue!
Properties
Requirements to be recognized as
discrete
:DISCRETE
is set to truepredecessor()
andsuccessor()
are implemented and do not panic
continuous
:DISCRETE
is set to false (default)predecessor()
andsuccessor()
are never to be called (they panic by default)
limited
:minimum()
andmaximum()
do not returnBound::Unbounded
bidirectional
minimum()
andmaximum()
returnBound::Unbounded
(default)
unidirectional
- either
minimum()
ormaximum()
does not returnBound::Unbounded
- either
Categories
discrete and limited
This is your typical primitive integer like u8
or i32
.
discrete, unlimited and bidirectional
An example for this kind of domain is BigInt
. The num-bigint
crate is used to optionally
provide an implementation.
discrete, unlimited and unidirectional
Like BigInt
, but limited in one direction: BigUint
.
continuous and limited
Because f32
or f64
do not implement Ord
, this trait can not be implemented for them directly.
Instead, using noisy_float
, all four types (N32
, N64
, R32
and R64
) have an optional
implementation. In terms of concrete values, an example domain could be [0.0, 1.0]
.
continuous, unlimited and bidirectional
This category requires an arbitrarily large float. So far no base/default implementation exists.
If you would like to suggest a crate that provides this type (it must implement Ord
!), please
leave an issue.
continuous, unlimited and unidirectional
This category requires an arbitrarily large float. So far no base/default implementation exists.
If you would like to suggest a crate that provides this type (it must implement Ord
!), please
leave an issue.
Associated Constants
const DISCRETE: bool
Defines if the domain is discrete or continuous.
Provided methods
#[must_use]fn predecessor(&self) -> Option<Self>
Returns the predecessor of self
.
Note
This method is only required if implemented on a discrete type and therefore has a default implementation which panics.
Panics
This function should panic if implemented on continuous types!
#[must_use]fn successor(&self) -> Option<Self>
Returns the successor of self
.
Note
This method is only required if implemented on a discrete type and therefore has a default implementation which panics.
Panics
This function should panic if implemented on continuous types!
#[must_use]fn minimum() -> Bound<Self>
Returns the smallest possible start bound.
The reason this returns a Bound
instead of Option<Self>
is that domains with this range
exist: (0.0, 1.0]
, making it necessary to allow for excluded values.
Note
By default it is assumed no minimum value exists and therefore Unbounded
is returned.
Assertion
It is assumed, that the full Domain
range is not empty, and therefore Self
should be
smaller or equal to the value contained in Self::maximum()
.
#[must_use]fn maximum() -> Bound<Self>
Returns the greatest possible end bound.
The reason this returns a Bound
instead of Option<Self>
is that domains with this range
exist: [0.0, 1.0)
, making it necessary to allow for excluded values.
Note
By default it is assumed no maximum value exists and therefore Unbounded
is returned.
Assertion
It is assumed, that the full Domain
range is not empty, and therefore Self
should be
greater or equal to the value contained in Self::minimum()
.
#[must_use]fn is_next_to(&self, other: &Self) -> bool
Calculates or statically defines if two values in a domain are next to each other.
Panics
This function should panic if implemented on continuous types!
Note
The default implementation uses predecessor()
and successor()
,
which should always panic if the domain is continuous.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
Returns true if there exists a b
so that with inputs a
and c
:
b.is_next_to(a) == true
b.is_next_to(c) == true
Panics
This function should panic if implemented on continuous types!
Implementations on Foreign Types
impl Domain for Ordering
[src]
const DISCRETE: bool
[src]
fn predecessor(&self) -> Option<Self>
[src]
fn successor(&self) -> Option<Self>
[src]
fn minimum() -> Bound<Self>
[src]
fn maximum() -> Bound<Self>
[src]
fn is_next_to(&self, other: &Self) -> bool
[src]
fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
Implementors
impl Domain for bool
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Returns:
self | Output |
---|---|
true | Some(false) |
false | None |
#[must_use]fn successor(&self) -> Option<Self>
[src]
Returns:
self | Output |
---|---|
true | None |
false | Some(true) |
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(false)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(true)
.
#[must_use]fn is_next_to(&self, other: &Self) -> bool
[src]
#[must_use]fn shares_neighbour_with(&self, _other: &Self) -> bool
[src]
impl Domain for char
[src]
This implementation recognizes invalid characters and skips them, reserved characters, however, are not.
const DISCRETE: bool
[src]
fn predecessor(&self) -> Option<Self>
[src]
If the invalid character boundary from the right side is hit, meaning self
is \u{0xe000}
,
the returned value will be \u{0xd7ff}
.
fn successor(&self) -> Option<Self>
[src]
If the invalid character boundary from the left side is hit, meaning self
is \u{0xd7ff}
,
the returned value will be \u{0xe000}
.
fn minimum() -> Bound<Self>
[src]
Returns \u{0x0}
.
fn maximum() -> Bound<Self>
[src]
Returns \u{10ffff}
.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
This method does not ignore invalid code points.
Example
use ranges::Domain; assert!(!'\u{df777}'.shares_neighbour_with(&'\u{e001}'));
impl Domain for i8
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Always returns Some(self - 1)
unless self
is Self::MIN
.
#[must_use]fn successor(&self) -> Option<Self>
[src]
Always returns Some(self + 1)
unless self
is Self::MAX
.
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(Self::MIN)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(Self::MAX)
.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
impl Domain for i16
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Always returns Some(self - 1)
unless self
is Self::MIN
.
#[must_use]fn successor(&self) -> Option<Self>
[src]
Always returns Some(self + 1)
unless self
is Self::MAX
.
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(Self::MIN)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(Self::MAX)
.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
impl Domain for i32
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Always returns Some(self - 1)
unless self
is Self::MIN
.
#[must_use]fn successor(&self) -> Option<Self>
[src]
Always returns Some(self + 1)
unless self
is Self::MAX
.
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(Self::MIN)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(Self::MAX)
.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
impl Domain for i64
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Always returns Some(self - 1)
unless self
is Self::MIN
.
#[must_use]fn successor(&self) -> Option<Self>
[src]
Always returns Some(self + 1)
unless self
is Self::MAX
.
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(Self::MIN)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(Self::MAX)
.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
impl Domain for i128
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Always returns Some(self - 1)
unless self
is Self::MIN
.
#[must_use]fn successor(&self) -> Option<Self>
[src]
Always returns Some(self + 1)
unless self
is Self::MAX
.
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(Self::MIN)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(Self::MAX)
.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
impl Domain for isize
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Always returns Some(self - 1)
unless self
is Self::MIN
.
#[must_use]fn successor(&self) -> Option<Self>
[src]
Always returns Some(self + 1)
unless self
is Self::MAX
.
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(Self::MIN)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(Self::MAX)
.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
impl Domain for u8
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Always returns Some(self - 1)
unless self
is zero.
#[must_use]fn successor(&self) -> Option<Self>
[src]
Always returns Some(self + 1)
unless self
is Self::MAX
.
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(Self::MIN)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(Self::MAX)
.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
impl Domain for u16
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Always returns Some(self - 1)
unless self
is zero.
#[must_use]fn successor(&self) -> Option<Self>
[src]
Always returns Some(self + 1)
unless self
is Self::MAX
.
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(Self::MIN)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(Self::MAX)
.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
impl Domain for u32
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Always returns Some(self - 1)
unless self
is zero.
#[must_use]fn successor(&self) -> Option<Self>
[src]
Always returns Some(self + 1)
unless self
is Self::MAX
.
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(Self::MIN)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(Self::MAX)
.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
impl Domain for u64
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Always returns Some(self - 1)
unless self
is zero.
#[must_use]fn successor(&self) -> Option<Self>
[src]
Always returns Some(self + 1)
unless self
is Self::MAX
.
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(Self::MIN)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(Self::MAX)
.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
impl Domain for u128
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Always returns Some(self - 1)
unless self
is zero.
#[must_use]fn successor(&self) -> Option<Self>
[src]
Always returns Some(self + 1)
unless self
is Self::MAX
.
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(Self::MIN)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(Self::MAX)
.
#[must_use]fn shares_neighbour_with(&self, other: &Self) -> bool
[src]
impl Domain for usize
[src]
const DISCRETE: bool
[src]
#[must_use]fn predecessor(&self) -> Option<Self>
[src]
Always returns Some(self - 1)
unless self
is zero.
#[must_use]fn successor(&self) -> Option<Self>
[src]
Always returns Some(self + 1)
unless self
is Self::MAX
.
#[must_use]fn minimum() -> Bound<Self>
[src]
Returns Included(Self::MIN)
.
#[must_use]fn maximum() -> Bound<Self>
[src]
Returns Included(Self::MAX)
.