Struct euclid::ScaleFactor
[−]
[src]
#[repr(C)]pub struct ScaleFactor<T, Src, Dst>(pub T, _);
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 ScaleFactor
. They
may be types without values, such as empty enums. For example:
use euclid::ScaleFactor; use euclid::Length; enum Mm {}; enum Inch {}; let mm_per_inch: ScaleFactor<f32, Inch, Mm> = ScaleFactor::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;
Methods
impl<T, Src, Dst> ScaleFactor<T, Src, Dst>
[src]
fn new(x: T) -> ScaleFactor<T, Src, Dst>
impl<T: Clone, Src, Dst> ScaleFactor<T, Src, Dst>
[src]
fn get(&self) -> T
impl<T: Clone + One + Div<T, Output = T>, Src, Dst> ScaleFactor<T, Src, Dst>
[src]
fn inv(&self) -> ScaleFactor<T, Dst, Src>
The inverse ScaleFactor (1.0 / self).
impl<T: NumCast + Clone, Src, Dst0> ScaleFactor<T, Src, Dst0>
[src]
fn cast<T1: NumCast + Clone>(&self) -> Option<ScaleFactor<T1, Src, Dst0>>
Cast from one numeric representation to another, preserving the units.
Trait Implementations
impl<T: HeapSizeOf, Src, Dst> HeapSizeOf for ScaleFactor<T, Src, Dst>
[src]
fn heap_size_of_children(&self) -> usize
Measure the size of any heap-allocated structures that hang off this value, but not the space taken up by the value itself (i.e. what size_of:: measures, more or less); that space is handled by the implementation of HeapSizeOf for Box below. Read more
impl<T, Src, Dst> Deserialize for ScaleFactor<T, Src, Dst> where
T: Deserialize,
[src]
T: Deserialize,
fn deserialize<D>(deserializer: D) -> Result<ScaleFactor<T, Src, Dst>, D::Error> where
D: Deserializer,
D: Deserializer,
Deserialize this value from the given Serde deserializer. Read more
impl<T, Src, Dst> Serialize for ScaleFactor<T, Src, Dst> where
T: Serialize,
[src]
T: Serialize,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<T: Clone + Mul<T, Output = T>, A, B, C> Mul<ScaleFactor<T, B, C>> for ScaleFactor<T, A, B>
[src]
type Output = ScaleFactor<T, A, C>
The resulting type after applying the *
operator
fn mul(self, other: ScaleFactor<T, B, C>) -> ScaleFactor<T, A, C>
The method for the *
operator
impl<T: Clone + Add<T, Output = T>, Src, Dst> Add for ScaleFactor<T, Src, Dst>
[src]
type Output = ScaleFactor<T, Src, Dst>
The resulting type after applying the +
operator
fn add(self, other: ScaleFactor<T, Src, Dst>) -> ScaleFactor<T, Src, Dst>
The method for the +
operator
impl<T: Clone + Sub<T, Output = T>, Src, Dst> Sub for ScaleFactor<T, Src, Dst>
[src]
type Output = ScaleFactor<T, Src, Dst>
The resulting type after applying the -
operator
fn sub(self, other: ScaleFactor<T, Src, Dst>) -> ScaleFactor<T, Src, Dst>
The method for the -
operator
impl<T: PartialEq, Src, Dst> PartialEq for ScaleFactor<T, Src, Dst>
[src]
fn eq(&self, other: &ScaleFactor<T, Src, Dst>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl<T: Clone, Src, Dst> Clone for ScaleFactor<T, Src, Dst>
[src]
fn clone(&self) -> ScaleFactor<T, Src, Dst>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more