LengthNum

Trait LengthNum 

Source
pub trait LengthNum:
    NumAssign
    + Bounded
    + Signed
    + PartialEq
    + PartialOrd
    + Clone
    + Copy
    + Debug
    + Zero {
    type Hashable: Eq + Hash + Debug;

    // Required methods
    fn to_hashable(&self) -> Self::Hashable;
    fn is_normal(&self) -> bool;
    fn from_f32(v: f32) -> Self;
    fn to_f32(self) -> f32;
    fn from_i32(v: i32) -> Self;

    // Provided methods
    fn mul_f32(self, v: f32) -> Self { ... }
    fn div_f32(self, v: f32) -> Self { ... }
    fn mul_i32(self, v: i32) -> Self { ... }
    fn div_i32(self, v: i32) -> Self { ... }
    fn upper_bound(self, v: Self) -> Self { ... }
    fn lower_bound(self, v: Self) -> Self { ... }
}
Expand description

A generic length trait.

A more specific number type is needed for CSS handling. In most cases f32 is what you need, but sometimes fixed-pointer types are preferred.

Required Associated Types§

Source

type Hashable: Eq + Hash + Debug

A target type used for hashing.

Required Methods§

Source

fn to_hashable(&self) -> Self::Hashable

Convert to the hashable type.

Source

fn is_normal(&self) -> bool

The number is normal (a.k.a. f32::is_normal) or not.

Source

fn from_f32(v: f32) -> Self

Convert from f32.

Source

fn to_f32(self) -> f32

Convert to f32.

Source

fn from_i32(v: i32) -> Self

Convert from i32.

Provided Methods§

Source

fn mul_f32(self, v: f32) -> Self

Multiply f32.

Source

fn div_f32(self, v: f32) -> Self

Divide f32.

Source

fn mul_i32(self, v: i32) -> Self

Multiply i32.

Source

fn div_i32(self, v: i32) -> Self

Divide i32.

Source

fn upper_bound(self, v: Self) -> Self

Limit the number with an upper bound.

Source

fn lower_bound(self, v: Self) -> Self

Limit the number with an lower bound.

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 LengthNum for f32

Source§

type Hashable = u32

Source§

fn to_hashable(&self) -> Self::Hashable

Source§

fn is_normal(&self) -> bool

Source§

fn from_f32(v: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_i32(v: i32) -> Self

Source§

impl LengthNum for f64

Source§

type Hashable = u64

Source§

fn to_hashable(&self) -> Self::Hashable

Source§

fn is_normal(&self) -> bool

Source§

fn from_f32(v: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_i32(v: i32) -> Self

Source§

impl<Frac> LengthNum for FixedI32<Frac>
where Frac: LeEqU32 + IsLessOrEqual<U30, Output = True>,

Source§

type Hashable = FixedI32<Frac>

Source§

fn to_hashable(&self) -> Self::Hashable

Source§

fn is_normal(&self) -> bool

Source§

fn from_f32(v: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_i32(v: i32) -> Self

Source§

impl<Frac> LengthNum for FixedI64<Frac>
where Frac: LeEqU64 + IsLessOrEqual<U62, Output = True>,

Source§

type Hashable = FixedI64<Frac>

Source§

fn to_hashable(&self) -> Self::Hashable

Source§

fn is_normal(&self) -> bool

Source§

fn from_f32(v: f32) -> Self

Source§

fn to_f32(self) -> f32

Source§

fn from_i32(v: i32) -> Self

Implementors§