[−][src]Struct euclid::Length
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.
Methods
impl<T, Unit> Length<T, Unit>
[src]
impl<T, Unit> Length<T, Unit>
impl<Unit, T: Clone> Length<T, Unit>
[src]
impl<Unit, T: Clone> Length<T, Unit>
impl<Unit, T0: NumCast + Clone> Length<T0, Unit>
[src]
impl<Unit, T0: NumCast + Clone> Length<T0, Unit>
pub fn cast<T1: NumCast + Clone>(&self) -> Length<T1, Unit>
[src]
pub fn cast<T1: NumCast + Clone>(&self) -> Length<T1, Unit>
Cast from one numeric representation to another, preserving the units.
pub fn try_cast<T1: NumCast + Clone>(&self) -> Option<Length<T1, Unit>>
[src]
pub fn try_cast<T1: NumCast + Clone>(&self) -> Option<Length<T1, Unit>>
Fallible cast from one numeric representation to another, preserving the units.
impl<T, U> Length<T, U> where
T: Copy + One + Add<Output = T> + Sub<Output = T> + Mul<Output = T>,
[src]
impl<T, U> Length<T, U> where
T: Copy + One + Add<Output = T> + Sub<Output = T> + Mul<Output = T>,
pub fn lerp(&self, other: Self, t: T) -> Self
[src]
pub fn lerp(&self, other: Self, t: T) -> Self
Linearly interpolate between this length and another length.
t
is expected to be between zero and one.
Trait Implementations
impl<Unit, T: Zero> Zero for Length<T, Unit>
[src]
impl<Unit, T: Zero> Zero for Length<T, Unit>
impl<Unit, T: Clone + PartialEq> PartialEq<Length<T, Unit>> for Length<T, Unit>
[src]
impl<Unit, T: Clone + PartialEq> PartialEq<Length<T, Unit>> for Length<T, Unit>
fn eq(&self, other: &Self) -> bool
[src]
fn eq(&self, other: &Self) -> bool
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]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<Unit, T: Clone + Eq> Eq for Length<T, Unit>
[src]
impl<Unit, T: Clone + Eq> Eq for Length<T, Unit>
impl<Unit, T: Clone + Ord> Ord for Length<T, Unit>
[src]
impl<Unit, T: Clone + Ord> Ord for Length<T, Unit>
fn cmp(&self, other: &Self) -> Ordering
[src]
fn cmp(&self, other: &Self) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl<Unit, T: Clone + PartialOrd> PartialOrd<Length<T, Unit>> for Length<T, Unit>
[src]
impl<Unit, T: Clone + PartialOrd> PartialOrd<Length<T, Unit>> for Length<T, Unit>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
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]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
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]
#[must_use]
fn le(&self, other: &Rhs) -> bool
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]
#[must_use]
fn gt(&self, other: &Rhs) -> bool
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]
#[must_use]
fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<T: Display + Clone, U> Display for Length<T, U>
[src]
impl<T: Display + Clone, U> Display for Length<T, U>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<T: Debug + Clone, U> Debug for Length<T, U>
[src]
impl<T: Debug + Clone, U> Debug for Length<T, U>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<U, T: Clone + Sub<T, Output = T>> Sub<Length<T, U>> for Length<T, U>
[src]
impl<U, T: Clone + Sub<T, Output = T>> Sub<Length<T, U>> for Length<T, U>
type Output = Length<T, U>
The resulting type after applying the -
operator.
fn sub(self, other: Length<T, U>) -> Self::Output
[src]
fn sub(self, other: Length<T, U>) -> Self::Output
Performs the -
operation.
impl<U, T: Clone + Add<T, Output = T>> Add<Length<T, U>> for Length<T, U>
[src]
impl<U, T: Clone + Add<T, Output = T>> Add<Length<T, U>> for Length<T, U>
type Output = Length<T, U>
The resulting type after applying the +
operator.
fn add(self, other: Length<T, U>) -> Length<T, U>
[src]
fn add(self, other: Length<T, U>) -> Length<T, U>
Performs the +
operation.
impl<T: Copy + Mul<T, Output = T>, U> Mul<T> for Length<T, U>
[src]
impl<T: Copy + Mul<T, Output = T>, U> Mul<T> for Length<T, U>
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, scale: T) -> Self
[src]
fn mul(self, scale: T) -> Self
Performs the *
operation.
impl<Src, Dst, T: Clone + Mul<T, Output = T>> Mul<TypedScale<T, Src, Dst>> for Length<T, Src>
[src]
impl<Src, Dst, T: Clone + Mul<T, Output = T>> Mul<TypedScale<T, Src, Dst>> for Length<T, Src>
type Output = Length<T, Dst>
The resulting type after applying the *
operator.
fn mul(self, scale: TypedScale<T, Src, Dst>) -> Length<T, Dst>
[src]
fn mul(self, scale: TypedScale<T, Src, Dst>) -> Length<T, Dst>
Performs the *
operation.
impl<Src, Dst, T: Clone + Div<T, Output = T>> Div<Length<T, Src>> for Length<T, Dst>
[src]
impl<Src, Dst, T: Clone + Div<T, Output = T>> Div<Length<T, Src>> for Length<T, Dst>
type Output = TypedScale<T, Src, Dst>
The resulting type after applying the /
operator.
fn div(self, other: Length<T, Src>) -> TypedScale<T, Src, Dst>
[src]
fn div(self, other: Length<T, Src>) -> TypedScale<T, Src, Dst>
Performs the /
operation.
impl<T: Copy + Div<T, Output = T>, U> Div<T> for Length<T, U>
[src]
impl<T: Copy + Div<T, Output = T>, U> Div<T> for Length<T, U>
type Output = Self
The resulting type after applying the /
operator.
fn div(self, scale: T) -> Self
[src]
fn div(self, scale: T) -> Self
Performs the /
operation.
impl<Src, Dst, T: Clone + Div<T, Output = T>> Div<TypedScale<T, Src, Dst>> for Length<T, Dst>
[src]
impl<Src, Dst, T: Clone + Div<T, Output = T>> Div<TypedScale<T, Src, Dst>> for Length<T, Dst>
type Output = Length<T, Src>
The resulting type after applying the /
operator.
fn div(self, scale: TypedScale<T, Src, Dst>) -> Length<T, Src>
[src]
fn div(self, scale: TypedScale<T, Src, Dst>) -> Length<T, Src>
Performs the /
operation.
impl<U, T: Clone + Neg<Output = T>> Neg for Length<T, U>
[src]
impl<U, T: Clone + Neg<Output = T>> Neg for Length<T, U>
type Output = Length<T, U>
The resulting type after applying the -
operator.
fn neg(self) -> Length<T, U>
[src]
fn neg(self) -> Length<T, U>
Performs the unary -
operation.
impl<U, T: Clone + AddAssign<T>> AddAssign<Length<T, U>> for Length<T, U>
[src]
impl<U, T: Clone + AddAssign<T>> AddAssign<Length<T, U>> for Length<T, U>
fn add_assign(&mut self, other: Length<T, U>)
[src]
fn add_assign(&mut self, other: Length<T, U>)
Performs the +=
operation.
impl<U, T: Clone + SubAssign<T>> SubAssign<Length<T, U>> for Length<T, U>
[src]
impl<U, T: Clone + SubAssign<T>> SubAssign<Length<T, U>> for Length<T, U>
fn sub_assign(&mut self, other: Length<T, U>)
[src]
fn sub_assign(&mut self, other: Length<T, U>)
Performs the -=
operation.
impl<T: Copy + Mul<T, Output = T>, U> MulAssign<T> for Length<T, U>
[src]
impl<T: Copy + Mul<T, Output = T>, U> MulAssign<T> for Length<T, U>
fn mul_assign(&mut self, scale: T)
[src]
fn mul_assign(&mut self, scale: T)
Performs the *=
operation.
impl<T: Copy + Div<T, Output = T>, U> DivAssign<T> for Length<T, U>
[src]
impl<T: Copy + Div<T, Output = T>, U> DivAssign<T> for Length<T, U>
fn div_assign(&mut self, scale: T)
[src]
fn div_assign(&mut self, scale: T)
Performs the /=
operation.
impl<T: Copy, Unit> Copy for Length<T, Unit>
[src]
impl<T: Copy, Unit> Copy for Length<T, Unit>
impl<T: Clone, Unit> Clone for Length<T, Unit>
[src]
impl<T: Clone, Unit> Clone for Length<T, Unit>
fn clone(&self) -> Self
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<T, Unit> Serialize for Length<T, Unit> where
T: Serialize,
[src]
impl<T, Unit> Serialize for Length<T, Unit> where
T: Serialize,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
[src]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de, Unit, T> Deserialize<'de> for Length<T, Unit> where
T: Deserialize<'de>,
[src]
impl<'de, Unit, T> Deserialize<'de> for Length<T, Unit> where
T: Deserialize<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<U, T: Clone + Saturating> Saturating for Length<T, U>
[src]
impl<U, T: Clone + Saturating> Saturating for Length<T, U>
fn saturating_add(self, other: Length<T, U>) -> Length<T, U>
[src]
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. Read more
fn saturating_sub(self, other: Length<T, U>) -> Length<T, U>
[src]
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. Read more
Auto Trait Implementations
impl<T, Unit> Send for Length<T, Unit> where
T: Send,
Unit: Send,
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> Sync for Length<T, Unit> where
T: Sync,
Unit: Sync,
Blanket Implementations
impl<T> Zero for T where
T: Zero,
[src]
impl<T> Zero for T where
T: Zero,
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> ToString for T where
T: Display + ?Sized,
[src]
impl<T> ToString for T where
T: Display + ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
type Owned = T
fn to_owned(&self) -> T
[src]
fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)
[src]
fn clone_into(&self, target: &mut T)
🔬 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> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,