pub trait Domain: Ord + Sized {
const DISCRETE: bool = false;
// Provided methods
fn predecessor(&self) -> Option<Self> { ... }
fn successor(&self) -> Option<Self> { ... }
fn minimum() -> Bound<Self> { ... }
fn maximum() -> Bound<Self> { ... }
fn is_next_to(&self, other: &Self) -> bool { ... }
fn shares_neighbour_with(&self, other: &Self) -> bool { ... }
}
Expand description
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.
Provided Associated Constants§
Provided Methods§
Sourcefn predecessor(&self) -> Option<Self>
fn predecessor(&self) -> Option<Self>
Sourcefn minimum() -> Bound<Self>
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()
.
Sourcefn maximum() -> Bound<Self>
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()
.
Sourcefn is_next_to(&self, other: &Self) -> bool
fn is_next_to(&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!
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Domain for bool
impl Domain for bool
Source§impl Domain for char
This implementation recognizes invalid characters and skips them,
reserved characters, however, are not.
impl Domain for char
This implementation recognizes invalid characters and skips them, reserved characters, however, are not.
Source§fn predecessor(&self) -> Option<Self>
fn predecessor(&self) -> Option<Self>
If the invalid character boundary from the right side is hit, meaning self
is \u{0xe000}
,
the returned value will be \u{0xd7ff}
.
Source§fn successor(&self) -> Option<Self>
fn successor(&self) -> Option<Self>
If the invalid character boundary from the left side is hit, meaning self
is \u{0xd7ff}
,
the returned value will be \u{0xe000}
.
This method does not ignore invalid code points.
§Example
use ranges::Domain;
assert!(!'\u{df777}'.shares_neighbour_with(&'\u{e001}'));