[][src]Trait ranges::Domain

pub trait Domain: Ord + Sized {
    const DISCRETE: bool;
#[must_use]    fn predecessor(&self) -> Option<Self> { ... }
#[must_use] fn successor(&self) -> Option<Self> { ... }
#[must_use] fn minimum() -> Bound<Self> { ... }
#[must_use] fn maximum() -> Bound<Self> { ... }
#[must_use] fn is_next_to(&self, other: &Self) -> bool { ... }
#[must_use] fn shares_neighbour_with(&self, other: &Self) -> bool { ... } }

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 true
    • predecessor() and successor() are implemented and do not panic
  • continuous:
    • DISCRETE is set to false (default)
    • predecessor() and successor() are never to be called (they panic by default)
  • limited:
    • minimum() and maximum() do not return Bound::Unbounded
  • bidirectional
    • minimum() and maximum() return Bound::Unbounded (default)
  • unidirectional
    • either minimum() or maximum() does not return Bound::Unbounded

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.

Loading content...

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!

Loading content...

Implementations on Foreign Types

impl Domain for Ordering[src]

Loading content...

Implementors

impl Domain for bool[src]

#[must_use]fn predecessor(&self) -> Option<Self>[src]

Returns:

selfOutput
trueSome(false)
falseNone

#[must_use]fn successor(&self) -> Option<Self>[src]

Returns:

selfOutput
trueNone
falseSome(true)

#[must_use]fn minimum() -> Bound<Self>[src]

Returns Included(false).

#[must_use]fn maximum() -> Bound<Self>[src]

Returns Included(true).

impl Domain for char[src]

This implementation recognizes invalid characters and skips them, reserved characters, however, are not.

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]

#[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).

impl Domain for i16[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).

impl Domain for i32[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).

impl Domain for i64[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).

impl Domain for i128[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).

impl Domain for isize[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).

impl Domain for u8[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).

impl Domain for u16[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).

impl Domain for u32[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).

impl Domain for u64[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).

impl Domain for u128[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).

impl Domain for usize[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).

Loading content...