Struct euclid::length::Length [] [src]

pub struct Length<Unit, T>(pub T, _);

A one-dimensional distance, with value represented by T and unit of measurement Unit.

T can be any numeric type, for example a primitive type like u64 or f32.

Unit is not used in the representation of a Length value. It is used only at compile time to ensure that a Length stored with one unit is converted explicitly before being used in an expression that requires a different unit. It may be a type without values, such as an empty enum.

You can multiply a Length by a scale_factor::ScaleFactor to convert it from one unit to another. See the ScaleFactor docs for an example.

Methods

impl<Unit, T> Length<Unit, T>

fn new(x: T) -> Length<Unit, T>

impl<Unit, T: Clone> Length<Unit, T>

fn get(&self) -> T

impl<Unit, T0: NumCast + Clone> Length<Unit, T0>

fn cast<T1: NumCast + Clone>(&self) -> Option<Length<Unit, T1>>

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

Trait Implementations

impl<U, T: Clone + Add<T, Output=T>> Add for Length<U, T>

type Output = Length<U, T>

fn add(self, other: Length<U, T>) -> Length<U, T>

impl<U, T: Clone + Sub<T, Output=T>> Sub<Length<U, T>> for Length<U, T>

type Output = Length<U, T>

fn sub(self, other: Length<U, T>) -> Self::Output

impl<Src, Dst, T: Clone + Div<T, Output=T>> Div<Length<Src, T>> for Length<Dst, T>

type Output = ScaleFactor<Src, Dst, T>

fn div(self, other: Length<Src, T>) -> ScaleFactor<Src, Dst, T>

impl<Src, Dst, T: Clone + Mul<T, Output=T>> Mul<ScaleFactor<Src, Dst, T>> for Length<Src, T>

type Output = Length<Dst, T>

fn mul(self, scale: ScaleFactor<Src, Dst, T>) -> Length<Dst, T>

impl<Src, Dst, T: Clone + Div<T, Output=T>> Div<ScaleFactor<Src, Dst, T>> for Length<Dst, T>

type Output = Length<Src, T>

fn div(self, scale: ScaleFactor<Src, Dst, T>) -> Length<Src, T>

impl<U, T: Clone + Neg<Output=T>> Neg for Length<U, T>

type Output = Length<U, T>

fn neg(self) -> Length<U, T>

impl<Unit, T: Clone> Clone for Length<Unit, T>

fn clone(&self) -> Length<Unit, T>

1.0.0fn clone_from(&mut self, source: &Self)

impl<Unit, T: Clone + PartialEq> PartialEq for Length<Unit, T>

fn eq(&self, other: &Length<Unit, T>) -> bool

1.0.0fn ne(&self, other: &Rhs) -> bool

impl<Unit, T: Clone + PartialOrd> PartialOrd for Length<Unit, T>

fn partial_cmp(&self, other: &Length<Unit, T>) -> Option<Ordering>

1.0.0fn lt(&self, other: &Rhs) -> bool

1.0.0fn le(&self, other: &Rhs) -> bool

1.0.0fn gt(&self, other: &Rhs) -> bool

1.0.0fn ge(&self, other: &Rhs) -> bool

impl<Unit, T: Clone + Eq> Eq for Length<Unit, T>

impl<Unit, T: Clone + Ord> Ord for Length<Unit, T>

fn cmp(&self, other: &Length<Unit, T>) -> Ordering

impl<Unit, T: Zero> Zero for Length<Unit, T>

fn zero() -> Length<Unit, T>

Derived Implementations

impl<Unit: Debug, T: Debug> Debug for Length<Unit, T>

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl<Unit: Encodable, T: Encodable> Encodable for Length<Unit, T>

fn encode<__SUnitT: Encoder>(&self, __arg_0: &mut __SUnitT) -> Result<(), __SUnitT::Error>

impl<Unit: Decodable, T: Decodable> Decodable for Length<Unit, T>

fn decode<__DUnitT: Decoder>(__arg_0: &mut __DUnitT) -> Result<Length<Unit, T>, __DUnitT::Error>

impl<Unit: Copy, T: Copy> Copy for Length<Unit, T>