Struct LengthArray

Source
pub struct LengthArray<const N: usize> { /* private fields */ }
Expand description

Array storage for a series of values and LengthUnit.

Implementations§

Source§

impl<const D: usize> LengthArray<D>

Source

pub fn new(values: [f64; D], unit: LengthUnit) -> Self

Create a new vector of LengthUnit.

Source

pub fn values(&self) -> &[f64; D]

Retrieve values associated with this [LengthSlice].

Source

pub fn values_mut(&mut self) -> &mut [f64; D]

Retrieve the mutable values associated with this [LengthSlice].

Source

pub fn yottameter(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::yottameter.

Source

pub fn zettameter(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::zettameter.

Source

pub fn exameter(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::exameter.

Source

pub fn petameter(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::petameter.

Source

pub fn terameter(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::terameter.

Source

pub fn gigameter(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::gigameter.

Source

pub fn megameter(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::megameter.

Source

pub fn kilometer(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::kilometer.

Source

pub fn hectometer(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::hectometer.

Source

pub fn decameter(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::decameter.

Source

pub fn meter(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::meter.

Source

pub fn decimeter(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::decimeter.

Source

pub fn centimeter(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::centimeter.

Source

pub fn millimeter(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::millimeter.

Source

pub fn micrometer(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::micrometer.

Source

pub fn nanometer(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::nanometer.

Source

pub fn picometer(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::picometer.

Source

pub fn femtometer(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::femtometer.

Source

pub fn attometer(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::attometer.

Source

pub fn zeptometer(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::zeptometer.

Source

pub fn yoctometer(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::yoctometer.

Source

pub fn angstrom(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::angstrom.

Source

pub fn bohr_radius(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::bohr_radius.

Source

pub fn atomic_unit_of_length(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::atomic_unit_of_length.

Source

pub fn astronomical_unit(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::astronomical_unit.

Source

pub fn chain(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::chain.

Source

pub fn fathom(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::fathom.

Source

pub fn fermi(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::fermi.

Source

pub fn foot(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::foot.

Source

pub fn kilofoot(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::kilofoot.

Source

pub fn foot_survey(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::foot_survey.

Source

pub fn inch(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::inch.

Source

pub fn light_year(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::light_year.

Source

pub fn microinch(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::microinch.

Source

pub fn micron(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::micron.

Source

pub fn mil(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::mil.

Source

pub fn mile(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::mile.

Source

pub fn mile_survey(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::mile_survey.

Source

pub fn nautical_mile(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::nautical_mile.

Source

pub fn parsec(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::parsec.

Source

pub fn pica_computer(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::pica_computer.

Source

pub fn pica_printers(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::pica_printers.

Source

pub fn point_computer(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::point_computer.

Source

pub fn point_printers(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::point_printers.

Source

pub fn rod(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::rod.

Source

pub fn yard(values: [f64; D]) -> Self

Create a new Length with units of LengthUnit::yard.

Source

pub fn to_yottameter(&self) -> Self

Source

pub fn to_zettameter(&self) -> Self

Source

pub fn to_exameter(&self) -> Self

Source

pub fn to_petameter(&self) -> Self

Source

pub fn to_terameter(&self) -> Self

Source

pub fn to_gigameter(&self) -> Self

Source

pub fn to_megameter(&self) -> Self

Source

pub fn to_kilometer(&self) -> Self

Source

pub fn to_hectometer(&self) -> Self

Source

pub fn to_decameter(&self) -> Self

Source

pub fn to_meter(&self) -> Self

Convert to LengthUnit::meter.

Source

pub fn to_decimeter(&self) -> Self

Source

pub fn to_centimeter(&self) -> Self

Source

pub fn to_millimeter(&self) -> Self

Source

pub fn to_micrometer(&self) -> Self

Source

pub fn to_nanometer(&self) -> Self

Source

pub fn to_picometer(&self) -> Self

Source

pub fn to_femtometer(&self) -> Self

Source

pub fn to_attometer(&self) -> Self

Source

pub fn to_zeptometer(&self) -> Self

Source

pub fn to_yoctometer(&self) -> Self

Source

pub fn to_angstrom(&self) -> Self

Source

pub fn to_bohr_radius(&self) -> Self

Source

pub fn to_atomic_unit_of_length(&self) -> Self

Source

pub fn to_astronomical_unit(&self) -> Self

Source

pub fn to_chain(&self) -> Self

Convert to LengthUnit::chain.

Source

pub fn to_fathom(&self) -> Self

Convert to LengthUnit::fathom.

Source

pub fn to_fermi(&self) -> Self

Convert to LengthUnit::fermi.

Source

pub fn to_foot(&self) -> Self

Convert to LengthUnit::foot.

Source

pub fn to_kilofoot(&self) -> Self

Source

pub fn to_foot_survey(&self) -> Self

Source

pub fn to_inch(&self) -> Self

Convert to LengthUnit::inch.

Source

pub fn to_light_year(&self) -> Self

Source

pub fn to_microinch(&self) -> Self

Source

pub fn to_micron(&self) -> Self

Convert to LengthUnit::micron.

Source

pub fn to_mil(&self) -> Self

Convert to LengthUnit::mil.

Source

pub fn to_mile(&self) -> Self

Convert to LengthUnit::mile.

Source

pub fn to_mile_survey(&self) -> Self

Source

pub fn to_nautical_mile(&self) -> Self

Source

pub fn to_parsec(&self) -> Self

Convert to LengthUnit::parsec.

Source

pub fn to_pica_computer(&self) -> Self

Source

pub fn to_pica_printers(&self) -> Self

Source

pub fn to_point_computer(&self) -> Self

Source

pub fn to_point_printers(&self) -> Self

Source

pub fn to_rod(&self) -> Self

Convert to LengthUnit::rod.

Source

pub fn to_yard(&self) -> Self

Convert to LengthUnit::yard.

Source

pub fn at(&self, index: usize) -> Length

Methods from Deref<Target = [f64; N]>§

1.57.0 · Source

pub fn as_slice(&self) -> &[T]

Returns a slice containing the entire array. Equivalent to &s[..].

1.57.0 · Source

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

Returns a mutable slice containing the entire array. Equivalent to &mut s[..].

1.77.0 · Source

pub fn each_ref(&self) -> [&T; N]

Borrows each element and returns an array of references with the same size as self.

§Example
let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);

This method is particularly useful if combined with other methods, like map. This way, you can avoid moving the original array if its elements are not Copy.

let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);

// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
1.77.0 · Source

pub fn each_mut(&mut self) -> [&mut T; N]

Borrows each element mutably and returns an array of mutable references with the same size as self.

§Example

let mut floats = [3.1, 2.7, -1.0];
let float_refs: [&mut f64; 3] = floats.each_mut();
*float_refs[0] = 0.0;
assert_eq!(float_refs, [&mut 0.0, &mut 2.7, &mut -1.0]);
assert_eq!(floats, [0.0, 2.7, -1.0]);
Source

pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])

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

Divides one array reference into two at an index.

The first will contain all indices from [0, M) (excluding the index M itself) and the second will contain all indices from [M, N) (excluding the index N itself).

§Panics

Panics if M > N.

§Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.split_array_ref::<0>();
   assert_eq!(left, &[]);
   assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<2>();
    assert_eq!(left, &[1, 2]);
    assert_eq!(right, &[3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<6>();
    assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
    assert_eq!(right, &[]);
}
Source

pub fn split_array_mut<const M: usize>(&mut self) -> (&mut [T; M], &mut [T])

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

Divides one mutable array reference into two at an index.

The first will contain all indices from [0, M) (excluding the index M itself) and the second will contain all indices from [M, N) (excluding the index N itself).

§Panics

Panics if M > N.

§Examples
#![feature(split_array)]

let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.split_array_mut::<2>();
assert_eq!(left, &mut [1, 0][..]);
assert_eq!(right, &mut [3, 0, 5, 6]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);
Source

pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])

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

Divides one array reference into two at an index from the end.

The first will contain all indices from [0, N - M) (excluding the index N - M itself) and the second will contain all indices from [N - M, N) (excluding the index N itself).

§Panics

Panics if M > N.

§Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.rsplit_array_ref::<0>();
   assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
   assert_eq!(right, &[]);
}

{
    let (left, right) = v.rsplit_array_ref::<2>();
    assert_eq!(left, &[1, 2, 3, 4]);
    assert_eq!(right, &[5, 6]);
}

{
    let (left, right) = v.rsplit_array_ref::<6>();
    assert_eq!(left, &[]);
    assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
Source

pub fn rsplit_array_mut<const M: usize>(&mut self) -> (&mut [T], &mut [T; M])

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

Divides one mutable array reference into two at an index from the end.

The first will contain all indices from [0, N - M) (excluding the index N - M itself) and the second will contain all indices from [N - M, N) (excluding the index N itself).

§Panics

Panics if M > N.

§Examples
#![feature(split_array)]

let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.rsplit_array_mut::<4>();
assert_eq!(left, &mut [1, 0]);
assert_eq!(right, &mut [3, 0, 5, 6][..]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);

Trait Implementations§

Source§

impl<const N: usize> Add for LengthArray<N>

Source§

type Output = LengthArray<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: LengthArray<N>) -> Self

Performs the + operation. Read more
Source§

impl<const N: usize> AddAssign for LengthArray<N>

Source§

fn add_assign(&mut self, rhs: LengthArray<N>)

Performs the += operation. Read more
Source§

impl<const N: usize> Clone for LengthArray<N>

Source§

fn clone(&self) -> LengthArray<N>

Returns a duplicate 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<const N: usize> Debug for LengthArray<N>

Source§

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

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

impl<const N: usize> Default for LengthArray<N>

Source§

fn default() -> Self

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

impl<const N: usize> Deref for LengthArray<N>

Source§

type Target = [f64; N]

The resulting type after dereferencing.
Source§

fn deref(&self) -> &[f64; N]

Dereferences the value.
Source§

impl<const N: usize> DerefMut for LengthArray<N>

Source§

fn deref_mut(&mut self) -> &mut [f64; N]

Mutably dereferences the value.
Source§

impl<const N: usize> Div<f64> for LengthArray<N>

Source§

type Output = LengthArray<N>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Self::Output

Performs the / operation. Read more
Source§

impl<const N: usize> DivAssign<f64> for LengthArray<N>

Source§

fn div_assign(&mut self, rhs: f64)

Performs the /= operation. Read more
Source§

impl<const N: usize> FixedSliceQuantity<LengthUnit, f64> for LengthArray<N>

Source§

fn unit(&self) -> LengthUnit

Return unit associated with this quantity
Source§

fn values(&self) -> &[f64]

Return values in quantity
Source§

fn values_mut(&mut self) -> &mut [f64]

Return mutable values in quantity
Source§

fn len(&self) -> usize

Return number of values in quantity
Source§

fn convert(&self, unit: LengthUnit) -> Self

Convert a unit of one UnitType to another of the same type. No validation of base unit is made.
Source§

fn convert_mut(&mut self, unit: LengthUnit)

Mutate current quantity, convering a unit of one UnitType to another of the same type. No validation of base unit is made.
Source§

fn try_convert(&self, unit: Units) -> Result<Self, RuntimeUnitError>
where Self: Sized,

Attempt to convert the unit given in unit to a UnitType. Base unit validation is made here.
Source§

impl<const N: usize> Mul<f64> for LengthArray<N>

Source§

type Output = LengthArray<N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize> MulAssign<f64> for LengthArray<N>

Source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
Source§

impl<const N: usize> PartialEq for LengthArray<N>

Source§

fn eq(&self, other: &LengthArray<N>) -> 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<const N: usize> Sub for LengthArray<N>

Source§

type Output = LengthArray<N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: LengthArray<N>) -> Self

Performs the - operation. Read more
Source§

impl<const N: usize> SubAssign for LengthArray<N>

Source§

fn sub_assign(&mut self, rhs: LengthArray<N>)

Performs the -= operation. Read more
Source§

impl<const N: usize> Copy for LengthArray<N>

Source§

impl<const N: usize> StructuralPartialEq for LengthArray<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for LengthArray<N>

§

impl<const N: usize> RefUnwindSafe for LengthArray<N>

§

impl<const N: usize> Send for LengthArray<N>

§

impl<const N: usize> Sync for LengthArray<N>

§

impl<const N: usize> Unpin for LengthArray<N>

§

impl<const N: usize> UnwindSafe for LengthArray<N>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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, 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.