[][src]Struct decorum::ConstrainedFloat

#[repr(transparent)]pub struct ConstrainedFloat<T, P> { /* fields omitted */ }

Floating-point proxy that provides total ordering, hashing, and constraints.

Wraps primitive floating-point types and provides implementions of numeric traits using a total ordering, including Ord, Eq, and Hash. ConstrainedFloat supports various contraints on the class of values that may be represented and panics if these constraints are violated.

This type is re-exported but should not (and cannot) be used directly. Use the type aliases Total, NotNan, and Finite instead.

Ordering

All proxy types use the following total ordering:

$$-\infin<\cdots<0<\cdots<\infin<\text{NaN}$$

See the cmp module for a description of the total ordering used to implement Ord and Eq.

Constraints

Constraints restrict the set of values that a proxy may take by disallowing certain classes or subsets of those values. If a constraint is violated (because a proxy type would need to take a value it disallows), the operation panics.

Constraints may disallow two broad classes of floating-point values: infinities and NaNs. Constraints are exposed by the Total, NotNan, and Finite type definitions. Note that Total uses a unit constraint, which enforces no constraints at all.

Methods

impl<T, P> ConstrainedFloat<T, P> where
    T: Primitive,
    P: Constraint<T>, 
[src]

pub fn from_inner(value: T) -> Self[src]

Converts a primitive floating-point value into a proxy.

The same behavior is provided by an implemention of the From trait.

Panics

This conversion and the implementation of the From trait will panic if the primitive floating-point value violates the constraints of the proxy.

Examples

Converting primitive floating-point values into proxies:

use decorum::R64;

fn f(x: R64) -> R64 {
    x * 2.0
}

// Conversion using `from_inner`.
let y = f(R64::from_inner(2.0));
// Conversion using `From`/`Into`.
let z = f(2.0.into());

Performing a conversion that panics:

use decorum::R64;

// `R64` does not allow `NaN`s, but `0.0 / 0.0` produces a `NaN`.
let x = R64::from_inner(0.0 / 0.0); // Panics.

pub fn into_inner(self) -> T[src]

Converts a proxy into a primitive floating-point value.

Examples

Converting a proxy into a primitive floating-point value:

use decorum::R64;

fn f() -> R64 {
    // ...
}

let x: f64 = f().into_inner();

pub fn from_subset<Q>(other: ConstrainedFloat<T, Q>) -> Self where
    Q: Constraint<T> + SubsetOf<P>, 
[src]

Converts a proxy into another proxy that is capable of representing a superset of the values that are members of its constraint.

Examples

Converting between compatible proxy types:

use decorum::{N64, R64};
use num::Zero;

let x = R64::zero();
let y = N64::from_subset(x);

pub fn into_superset<Q>(self) -> ConstrainedFloat<T, Q> where
    Q: Constraint<T> + SupersetOf<P>, 
[src]

Converts a proxy into another proxy that is capable of representing a superset of the values that are members of its constraint.

Examples

Converting between compatible proxy types:

use decorum::{N64, R64};
use num::Zero;

let x = R64::zero();
let y: N64 = x.into_superset();

Trait Implementations

impl<T, P> AbsDiffEq<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: AbsDiffEq<Epsilon = T> + Encoding + Nan + Primitive,
    P: Constraint<T>, 
[src]

type Epsilon = Self

Used for specifying relative comparisons.

impl<T, P> Add<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

type Output = Self

The resulting type after applying the + operator.

impl<T, P> Add<T> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

type Output = Self

The resulting type after applying the + operator.

impl<T, P> AddAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> AddAssign<T> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> AsRef<T> for ConstrainedFloat<T, P> where
    T: Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> Bounded for ConstrainedFloat<T, P> where
    T: Encoding + Primitive,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T: Clone, P: Clone> Clone for ConstrainedFloat<T, P>[src]

impl<T: Copy, P: Copy> Copy for ConstrainedFloat<T, P>[src]

impl<T, P> Debug for ConstrainedFloat<T, P> where
    T: Debug + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> Default for ConstrainedFloat<T, P> where
    T: Default + Primitive,
    P: Constraint<T>, 
[src]

impl<'de, T, P> Deserialize<'de> for ConstrainedFloat<T, P> where
    T: Deserialize<'de>, 
[src]

impl<T, P> Display for ConstrainedFloat<T, P> where
    T: Display + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> Div<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

type Output = Self

The resulting type after applying the / operator.

impl<T, P> Div<T> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

type Output = Self

The resulting type after applying the / operator.

impl<T, P> DivAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> DivAssign<T> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> Encoding for ConstrainedFloat<T, P> where
    T: Encoding + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> Eq for ConstrainedFloat<T, P> where
    T: Encoding + Nan + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> Float for ConstrainedFloat<T, P> where
    T: Encoding + Float + Infinite + IntrinsicOrd + Nan + Primitive + Real,
    P: Constraint<T> + Member<InfiniteClass> + Member<NanClass> + Member<RealClass>, 
[src]

impl<T, P> FloatConst for ConstrainedFloat<T, P> where
    T: Encoding + Nan + Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T> From<ConstrainedFloat<T, FiniteConstraint<T>>> for Total<T> where
    T: Infinite + Nan + Primitive
[src]

impl<T> From<ConstrainedFloat<T, FiniteConstraint<T>>> for NotNan<T> where
    T: Infinite + Nan + Primitive
[src]

impl<T> From<ConstrainedFloat<T, NotNanConstraint<T>>> for Total<T> where
    T: Nan + Primitive
[src]

impl<P> From<ConstrainedFloat<f32, P>> for f32 where
    P: Constraint<f32>, 
[src]

impl<P> From<ConstrainedFloat<f64, P>> for f64 where
    P: Constraint<f64>, 
[src]

impl<T, P> From<T> for ConstrainedFloat<T, P> where
    T: Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> FromPrimitive for ConstrainedFloat<T, P> where
    T: FromPrimitive + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> FromStr for ConstrainedFloat<T, P> where
    T: FromStr + Primitive,
    P: Constraint<T>, 
[src]

type Err = <T as FromStr>::Err

The associated error which can be returned from parsing.

impl<T, P> Hash for ConstrainedFloat<T, P> where
    T: Encoding + Nan + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> Infinite for ConstrainedFloat<T, P> where
    T: Infinite + Primitive,
    P: Constraint<T> + Member<InfiniteClass>, 
[src]

impl<T, P> IntrinsicOrd for ConstrainedFloat<T, P> where
    T: Encoding + IntrinsicOrd + Nan + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> LowerExp for ConstrainedFloat<T, P> where
    T: LowerExp + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> Mul<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

type Output = Self

The resulting type after applying the * operator.

impl<T, P> Mul<T> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

type Output = Self

The resulting type after applying the * operator.

impl<T, P> MulAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> MulAssign<T> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> Nan for ConstrainedFloat<T, P> where
    T: Nan + Primitive,
    P: Constraint<T> + Member<NanClass>, 
[src]

impl<T, P> Neg for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

type Output = Self

The resulting type after applying the - operator.

impl<T, P> Num for ConstrainedFloat<T, P> where
    Self: PartialEq,
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

type FromStrRadixErr = ()

impl<T, P> NumCast for ConstrainedFloat<T, P> where
    T: NumCast + Primitive + ToPrimitive,
    P: Constraint<T>, 
[src]

impl<T, P> One for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> Ord for ConstrainedFloat<T, P> where
    T: Encoding + Nan + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> PartialEq<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Encoding + Nan + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> PartialEq<T> for ConstrainedFloat<T, P> where
    T: Encoding + Nan + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> PartialOrd<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Encoding + Nan + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> PartialOrd<T> for ConstrainedFloat<T, P> where
    T: Encoding + Nan + PartialOrd + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> Product<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> Real for ConstrainedFloat<T, P> where
    T: Encoding + Nan + Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> RelativeEq<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Encoding + Nan + Primitive + RelativeEq<Epsilon = T>,
    P: Constraint<T>, 
[src]

impl<T, P> Rem<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

type Output = Self

The resulting type after applying the % operator.

impl<T, P> Rem<T> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

type Output = Self

The resulting type after applying the % operator.

impl<T, P> RemAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> RemAssign<T> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> Serialize for ConstrainedFloat<T, P> where
    T: Serialize
[src]

impl<T, P> Signed for ConstrainedFloat<T, P> where
    T: Encoding + Nan + Primitive + Real + Signed,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> Sub<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

type Output = Self

The resulting type after applying the - operator.

impl<T, P> Sub<T> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

type Output = Self

The resulting type after applying the - operator.

impl<T, P> SubAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> SubAssign<T> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> Sum<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

impl<T, P> ToPrimitive for ConstrainedFloat<T, P> where
    T: Primitive + ToPrimitive,
    P: Constraint<T>, 
[src]

impl<T, P> UlpsEq<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
    T: Encoding + Nan + Primitive + UlpsEq<Epsilon = T>,
    P: Constraint<T>, 
[src]

impl<T, P> UpperExp for ConstrainedFloat<T, P> where
    T: UpperExp + Primitive,
    P: Constraint<T>, 
[src]

impl<T, P> Zero for ConstrainedFloat<T, P> where
    T: Primitive + Real,
    P: Constraint<T> + Member<RealClass>, 
[src]

Auto Trait Implementations

impl<T, P> RefUnwindSafe for ConstrainedFloat<T, P> where
    P: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, P> Send for ConstrainedFloat<T, P> where
    P: Send,
    T: Send

impl<T, P> Sync for ConstrainedFloat<T, P> where
    P: Sync,
    T: Sync

impl<T, P> Unpin for ConstrainedFloat<T, P> where
    P: Unpin,
    T: Unpin

impl<T, P> UnwindSafe for ConstrainedFloat<T, P> where
    P: UnwindSafe,
    T: UnwindSafe

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> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

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

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

impl<T> NumAssign for T where
    T: Num + NumAssignOps<T>, 
[src]

impl<T, Rhs> NumAssignOps<Rhs> for T where
    T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>, 
[src]

impl<T, Rhs, Output> NumOps<Rhs, Output> for T where
    T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>, 
[src]

impl<T> Real for T where
    T: Float
[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.