Struct euclid::Length[][src]

#[repr(C)]
pub struct Length<T, Unit>(pub T, _);
Expand description

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::Scale to convert it from one unit to another. See the Scale docs for an example.

Implementations

impl<T, U> Length<T, U>[src]

pub const fn new(x: T) -> Self[src]

Associate a value with a unit of measure.

impl<T: Clone, U> Length<T, U>[src]

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

Unpack the underlying value from the wrapper.

pub fn cast_unit<V>(self) -> Length<T, V>[src]

Cast the unit

pub fn lerp(self, other: Self, t: T) -> Self where
    T: One + Sub<Output = T> + Mul<Output = T> + Add<Output = T>, 
[src]

Linearly interpolate between this length and another length.

Example

use euclid::default::Length;

let from = Length::new(0.0);
let to = Length::new(8.0);

assert_eq!(from.lerp(to, -1.0), Length::new(-8.0));
assert_eq!(from.lerp(to,  0.0), Length::new( 0.0));
assert_eq!(from.lerp(to,  0.5), Length::new( 4.0));
assert_eq!(from.lerp(to,  1.0), Length::new( 8.0));
assert_eq!(from.lerp(to,  2.0), Length::new(16.0));

impl<T: PartialOrd, U> Length<T, U>[src]

pub fn min(self, other: Self) -> Self[src]

Returns minimum between this length and another length.

pub fn max(self, other: Self) -> Self[src]

Returns maximum between this length and another length.

impl<T: NumCast + Clone, U> Length<T, U>[src]

pub fn cast<NewT: NumCast>(self) -> Length<NewT, U>[src]

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

pub fn try_cast<NewT: NumCast>(self) -> Option<Length<NewT, U>>[src]

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

Trait Implementations

impl<T: Add + Copy, U> Add<&'_ Length<T, U>> for Length<T, U>[src]

type Output = Length<T::Output, U>

The resulting type after applying the + operator.

fn add(self, other: &Self) -> Self::Output[src]

Performs the + operation. Read more

impl<T: Add, U> Add<Length<T, U>> for Length<T, U>[src]

type Output = Length<T::Output, U>

The resulting type after applying the + operator.

fn add(self, other: Self) -> Self::Output[src]

Performs the + operation. Read more

impl<T: AddAssign, U> AddAssign<Length<T, U>> for Length<T, U>[src]

fn add_assign(&mut self, other: Self)[src]

Performs the += operation. Read more

impl<U, T: ApproxEq<T>> ApproxEq<T> for Length<T, U>[src]

fn approx_epsilon() -> T[src]

Default epsilon value

fn approx_eq_eps(&self, other: &Length<T, U>, approx_epsilon: &T) -> bool[src]

Returns true is this object is approximately equal to the other one, using a provided epsilon value. Read more

fn approx_eq(&self, other: &Self) -> bool[src]

Returns true is this object is approximately equal to the other one, using the approx_epsilon() epsilon value. Read more

impl<T: Clone, U> Clone for Length<T, U>[src]

fn clone(&self) -> Self[src]

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

impl<T: Debug, U> Debug for Length<T, U>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<T: Default, U> Default for Length<T, U>[src]

fn default() -> Self[src]

Returns the “default value” for a type. Read more

impl<Src, Dst, T: Div> Div<Length<T, Src>> for Length<T, Dst>[src]

type Output = Scale<T::Output, Src, Dst>

The resulting type after applying the / operator.

fn div(self, other: Length<T, Src>) -> Self::Output[src]

Performs the / operation. Read more

impl<Src, Dst, T: Div> Div<Scale<T, Src, Dst>> for Length<T, Dst>[src]

type Output = Length<T::Output, Src>

The resulting type after applying the / operator.

fn div(self, scale: Scale<T, Src, Dst>) -> Self::Output[src]

Performs the / operation. Read more

impl<T: Div, U> Div<T> for Length<T, U>[src]

type Output = Length<T::Output, U>

The resulting type after applying the / operator.

fn div(self, scale: T) -> Self::Output[src]

Performs the / operation. Read more

impl<T: Copy + Div<T, Output = T>, U> DivAssign<T> for Length<T, U>[src]

fn div_assign(&mut self, scale: T)[src]

Performs the /= operation. Read more

impl<T: Hash, U> Hash for Length<T, U>[src]

fn hash<H: Hasher>(&self, h: &mut H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl<Src, Dst, T: Mul> Mul<Scale<T, Src, Dst>> for Length<T, Src>[src]

type Output = Length<T::Output, Dst>

The resulting type after applying the * operator.

fn mul(self, scale: Scale<T, Src, Dst>) -> Self::Output[src]

Performs the * operation. Read more

impl<T: Mul, U> Mul<T> for Length<T, U>[src]

type Output = Length<T::Output, U>

The resulting type after applying the * operator.

fn mul(self, scale: T) -> Self::Output[src]

Performs the * operation. Read more

impl<T: Copy + Mul<T, Output = T>, U> MulAssign<T> for Length<T, U>[src]

fn mul_assign(&mut self, scale: T)[src]

Performs the *= operation. Read more

impl<U, T: Neg> Neg for Length<T, U>[src]

type Output = Length<T::Output, U>

The resulting type after applying the - operator.

fn neg(self) -> Self::Output[src]

Performs the unary - operation. Read more

impl<T: Ord, U> Ord for Length<T, U>[src]

fn cmp(&self, other: &Self) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl<T: PartialEq, U> PartialEq<Length<T, U>> for Length<T, U>[src]

fn eq(&self, other: &Self) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<T: PartialOrd, U> PartialOrd<Length<T, U>> for Length<T, U>[src]

fn partial_cmp(&self, other: &Self) -> Option<Ordering>[src]

This method returns an ordering between self and other values if one exists. Read more

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T: Saturating, U> Saturating for Length<T, U>[src]

fn saturating_add(self, other: Self) -> Self[src]

Saturating addition operator. Returns a+b, saturating at the numeric bounds instead of overflowing. Read more

fn saturating_sub(self, other: Self) -> Self[src]

Saturating subtraction operator. Returns a-b, saturating at the numeric bounds instead of overflowing. Read more

impl<T: Sub, U> Sub<Length<T, U>> for Length<T, U>[src]

type Output = Length<T::Output, U>

The resulting type after applying the - operator.

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

Performs the - operation. Read more

impl<T: SubAssign, U> SubAssign<Length<T, U>> for Length<T, U>[src]

fn sub_assign(&mut self, other: Self)[src]

Performs the -= operation. Read more

impl<'a, T: 'a + Add<Output = T> + Copy + Zero, U: 'a> Sum<&'a Length<T, U>> for Length<T, U>[src]

fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self[src]

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

impl<T: Add<Output = T> + Zero, U> Sum<Length<T, U>> for Length<T, U>[src]

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self[src]

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

impl<T: Zero, U> Zero for Length<T, U>[src]

fn zero() -> Self[src]

impl<T: Copy, U> Copy for Length<T, U>[src]

impl<T: Eq, U> Eq for Length<T, U>[src]

Auto Trait Implementations

impl<T, Unit> RefUnwindSafe for Length<T, Unit> where
    T: RefUnwindSafe,
    Unit: RefUnwindSafe

impl<T, Unit> Send for Length<T, Unit> where
    T: Send,
    Unit: Send

impl<T, Unit> Sync for Length<T, Unit> where
    T: Sync,
    Unit: Sync

impl<T, Unit> Unpin for Length<T, Unit> where
    T: Unpin,
    Unit: Unpin

impl<T, Unit> UnwindSafe for Length<T, Unit> where
    T: UnwindSafe,
    Unit: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.