Struct euclid::TypedScale

source ·
#[repr(C)]
pub struct TypedScale<T, Src, Dst>(pub T, _);
Expand description

A scaling factor between two different units of measurement.

This is effectively a type-safe float, intended to be used in combination with other types like length::Length to enforce conversion between systems of measurement at compile time.

Src and Dst represent the units before and after multiplying a value by a TypedScale. They may be types without values, such as empty enums. For example:

use euclid::TypedScale;
use euclid::Length;
enum Mm {};
enum Inch {};

let mm_per_inch: TypedScale<f32, Inch, Mm> = TypedScale::new(25.4);

let one_foot: Length<f32, Inch> = Length::new(12.0);
let one_foot_in_mm: Length<f32, Mm> = one_foot * mm_per_inch;

Tuple Fields

0: T

Implementations

Identity scaling, could be used to safely transit from one space to another.

The inverse TypedScale (1.0 / self).

Cast from one numeric representation to another, preserving the units.

Fallible cast from one numeric representation to another, preserving the units.

Returns the given point transformed by this scale.

Returns the given vector transformed by this scale.

Returns the given vector transformed by this scale.

Returns the given rect transformed by this scale.

Returns the inverse of this scale.

Returns true if this scale has no effect.

Trait Implementations

The resulting type after applying the + operator.
Performs the + operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.