Struct Length

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

Tuple Fields§

§0: T

Implementations§

Source§

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

Source

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

Source§

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

Source

pub fn get(&self) -> T

Source§

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

Source

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

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

Source

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

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

Source§

impl<T, U> Length<T, U>
where T: One + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Copy,

Source

pub fn lerp(&self, other: Length<T, U>, t: T) -> Length<T, U>

Linearly interpolate between this length and another length.

t is expected to be between zero and one.

Trait Implementations§

Source§

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

Source§

type Output = Length<T, U>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<U, T> AddAssign for Length<T, U>
where T: Clone + AddAssign,

Source§

fn add_assign(&mut self, other: Length<T, U>)

Performs the += operation. Read more
Source§

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

Source§

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

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T, U> Debug for Length<T, U>
where T: Debug + Clone,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T, U> Display for Length<T, U>
where T: Display + Clone,

Source§

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

Formats the value using the given formatter. Read more
Source§

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

Source§

type Output = TypedScale<T, Src, Dst>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T, U> Div<T> for Length<T, U>
where T: Copy + Div<Output = T>,

Source§

type Output = Length<T, U>

The resulting type after applying the / operator.
Source§

fn div(self, scale: T) -> Length<T, U>

Performs the / operation. Read more
Source§

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

Source§

type Output = Length<T, Src>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T, U> DivAssign<T> for Length<T, U>
where T: Copy + Div<Output = T>,

Source§

fn div_assign(&mut self, scale: T)

Performs the /= operation. Read more
Source§

impl<T, U> Mul<T> for Length<T, U>
where T: Copy + Mul<Output = T>,

Source§

type Output = Length<T, U>

The resulting type after applying the * operator.
Source§

fn mul(self, scale: T) -> Length<T, U>

Performs the * operation. Read more
Source§

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

Source§

type Output = Length<T, Dst>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T, U> MulAssign<T> for Length<T, U>
where T: Copy + Mul<Output = T>,

Source§

fn mul_assign(&mut self, scale: T)

Performs the *= operation. Read more
Source§

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

Source§

type Output = Length<T, U>

The resulting type after applying the - operator.
Source§

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

Performs the unary - operation. Read more
Source§

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

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

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

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

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<U, T> Saturating for Length<T, U>
where T: Clone + Saturating,

Source§

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

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

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

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

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

Source§

type Output = Length<T, U>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<U, T> SubAssign for Length<T, U>
where T: Clone + SubAssign,

Source§

fn sub_assign(&mut self, other: Length<T, U>)

Performs the -= operation. Read more
Source§

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

Source§

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

Source§

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

Source§

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

Auto Trait Implementations§

§

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

§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.