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>
impl<const D: usize> LengthArray<D>
Sourcepub fn new(values: [f64; D], unit: LengthUnit) -> Self
pub fn new(values: [f64; D], unit: LengthUnit) -> Self
Create a new vector of LengthUnit
.
Sourcepub fn values_mut(&mut self) -> &mut [f64; D]
pub fn values_mut(&mut self) -> &mut [f64; D]
Retrieve the mutable values associated with this [LengthSlice
].
Sourcepub fn yottameter(values: [f64; D]) -> Self
pub fn yottameter(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::yottameter
.
Sourcepub fn zettameter(values: [f64; D]) -> Self
pub fn zettameter(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::zettameter
.
Sourcepub fn exameter(values: [f64; D]) -> Self
pub fn exameter(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::exameter
.
Sourcepub fn petameter(values: [f64; D]) -> Self
pub fn petameter(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::petameter
.
Sourcepub fn terameter(values: [f64; D]) -> Self
pub fn terameter(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::terameter
.
Sourcepub fn gigameter(values: [f64; D]) -> Self
pub fn gigameter(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::gigameter
.
Sourcepub fn megameter(values: [f64; D]) -> Self
pub fn megameter(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::megameter
.
Sourcepub fn kilometer(values: [f64; D]) -> Self
pub fn kilometer(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::kilometer
.
Sourcepub fn hectometer(values: [f64; D]) -> Self
pub fn hectometer(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::hectometer
.
Sourcepub fn decameter(values: [f64; D]) -> Self
pub fn decameter(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::decameter
.
Sourcepub fn decimeter(values: [f64; D]) -> Self
pub fn decimeter(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::decimeter
.
Sourcepub fn centimeter(values: [f64; D]) -> Self
pub fn centimeter(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::centimeter
.
Sourcepub fn millimeter(values: [f64; D]) -> Self
pub fn millimeter(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::millimeter
.
Sourcepub fn micrometer(values: [f64; D]) -> Self
pub fn micrometer(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::micrometer
.
Sourcepub fn nanometer(values: [f64; D]) -> Self
pub fn nanometer(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::nanometer
.
Sourcepub fn picometer(values: [f64; D]) -> Self
pub fn picometer(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::picometer
.
Sourcepub fn femtometer(values: [f64; D]) -> Self
pub fn femtometer(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::femtometer
.
Sourcepub fn attometer(values: [f64; D]) -> Self
pub fn attometer(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::attometer
.
Sourcepub fn zeptometer(values: [f64; D]) -> Self
pub fn zeptometer(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::zeptometer
.
Sourcepub fn yoctometer(values: [f64; D]) -> Self
pub fn yoctometer(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::yoctometer
.
Sourcepub fn angstrom(values: [f64; D]) -> Self
pub fn angstrom(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::angstrom
.
Sourcepub fn bohr_radius(values: [f64; D]) -> Self
pub fn bohr_radius(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::bohr_radius
.
Sourcepub fn atomic_unit_of_length(values: [f64; D]) -> Self
pub fn atomic_unit_of_length(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::atomic_unit_of_length
.
Sourcepub fn astronomical_unit(values: [f64; D]) -> Self
pub fn astronomical_unit(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::astronomical_unit
.
Sourcepub fn kilofoot(values: [f64; D]) -> Self
pub fn kilofoot(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::kilofoot
.
Sourcepub fn foot_survey(values: [f64; D]) -> Self
pub fn foot_survey(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::foot_survey
.
Sourcepub fn light_year(values: [f64; D]) -> Self
pub fn light_year(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::light_year
.
Sourcepub fn microinch(values: [f64; D]) -> Self
pub fn microinch(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::microinch
.
Sourcepub fn mile_survey(values: [f64; D]) -> Self
pub fn mile_survey(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::mile_survey
.
Sourcepub fn nautical_mile(values: [f64; D]) -> Self
pub fn nautical_mile(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::nautical_mile
.
Sourcepub fn pica_computer(values: [f64; D]) -> Self
pub fn pica_computer(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::pica_computer
.
Sourcepub fn pica_printers(values: [f64; D]) -> Self
pub fn pica_printers(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::pica_printers
.
Sourcepub fn point_computer(values: [f64; D]) -> Self
pub fn point_computer(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::point_computer
.
Sourcepub fn point_printers(values: [f64; D]) -> Self
pub fn point_printers(values: [f64; D]) -> Self
Create a new Length
with units of LengthUnit::point_printers
.
Sourcepub fn to_yottameter(&self) -> Self
pub fn to_yottameter(&self) -> Self
Convert to LengthUnit::yottameter
.
Sourcepub fn to_zettameter(&self) -> Self
pub fn to_zettameter(&self) -> Self
Convert to LengthUnit::zettameter
.
Sourcepub fn to_exameter(&self) -> Self
pub fn to_exameter(&self) -> Self
Convert to LengthUnit::exameter
.
Sourcepub fn to_petameter(&self) -> Self
pub fn to_petameter(&self) -> Self
Convert to LengthUnit::petameter
.
Sourcepub fn to_terameter(&self) -> Self
pub fn to_terameter(&self) -> Self
Convert to LengthUnit::terameter
.
Sourcepub fn to_gigameter(&self) -> Self
pub fn to_gigameter(&self) -> Self
Convert to LengthUnit::gigameter
.
Sourcepub fn to_megameter(&self) -> Self
pub fn to_megameter(&self) -> Self
Convert to LengthUnit::megameter
.
Sourcepub fn to_kilometer(&self) -> Self
pub fn to_kilometer(&self) -> Self
Convert to LengthUnit::kilometer
.
Sourcepub fn to_hectometer(&self) -> Self
pub fn to_hectometer(&self) -> Self
Convert to LengthUnit::hectometer
.
Sourcepub fn to_decameter(&self) -> Self
pub fn to_decameter(&self) -> Self
Convert to LengthUnit::decameter
.
Sourcepub fn to_meter(&self) -> Self
pub fn to_meter(&self) -> Self
Convert to LengthUnit::meter
.
Sourcepub fn to_decimeter(&self) -> Self
pub fn to_decimeter(&self) -> Self
Convert to LengthUnit::decimeter
.
Sourcepub fn to_centimeter(&self) -> Self
pub fn to_centimeter(&self) -> Self
Convert to LengthUnit::centimeter
.
Sourcepub fn to_millimeter(&self) -> Self
pub fn to_millimeter(&self) -> Self
Convert to LengthUnit::millimeter
.
Sourcepub fn to_micrometer(&self) -> Self
pub fn to_micrometer(&self) -> Self
Convert to LengthUnit::micrometer
.
Sourcepub fn to_nanometer(&self) -> Self
pub fn to_nanometer(&self) -> Self
Convert to LengthUnit::nanometer
.
Sourcepub fn to_picometer(&self) -> Self
pub fn to_picometer(&self) -> Self
Convert to LengthUnit::picometer
.
Sourcepub fn to_femtometer(&self) -> Self
pub fn to_femtometer(&self) -> Self
Convert to LengthUnit::femtometer
.
Sourcepub fn to_attometer(&self) -> Self
pub fn to_attometer(&self) -> Self
Convert to LengthUnit::attometer
.
Sourcepub fn to_zeptometer(&self) -> Self
pub fn to_zeptometer(&self) -> Self
Convert to LengthUnit::zeptometer
.
Sourcepub fn to_yoctometer(&self) -> Self
pub fn to_yoctometer(&self) -> Self
Convert to LengthUnit::yoctometer
.
Sourcepub fn to_angstrom(&self) -> Self
pub fn to_angstrom(&self) -> Self
Convert to LengthUnit::angstrom
.
Sourcepub fn to_bohr_radius(&self) -> Self
pub fn to_bohr_radius(&self) -> Self
Convert to LengthUnit::bohr_radius
.
Sourcepub fn to_atomic_unit_of_length(&self) -> Self
pub fn to_atomic_unit_of_length(&self) -> Self
Convert to LengthUnit::atomic_unit_of_length
.
Sourcepub fn to_astronomical_unit(&self) -> Self
pub fn to_astronomical_unit(&self) -> Self
Convert to LengthUnit::astronomical_unit
.
Sourcepub fn to_chain(&self) -> Self
pub fn to_chain(&self) -> Self
Convert to LengthUnit::chain
.
Sourcepub fn to_fathom(&self) -> Self
pub fn to_fathom(&self) -> Self
Convert to LengthUnit::fathom
.
Sourcepub fn to_fermi(&self) -> Self
pub fn to_fermi(&self) -> Self
Convert to LengthUnit::fermi
.
Sourcepub fn to_foot(&self) -> Self
pub fn to_foot(&self) -> Self
Convert to LengthUnit::foot
.
Sourcepub fn to_kilofoot(&self) -> Self
pub fn to_kilofoot(&self) -> Self
Convert to LengthUnit::kilofoot
.
Sourcepub fn to_foot_survey(&self) -> Self
pub fn to_foot_survey(&self) -> Self
Convert to LengthUnit::foot_survey
.
Sourcepub fn to_inch(&self) -> Self
pub fn to_inch(&self) -> Self
Convert to LengthUnit::inch
.
Sourcepub fn to_light_year(&self) -> Self
pub fn to_light_year(&self) -> Self
Convert to LengthUnit::light_year
.
Sourcepub fn to_microinch(&self) -> Self
pub fn to_microinch(&self) -> Self
Convert to LengthUnit::microinch
.
Sourcepub fn to_micron(&self) -> Self
pub fn to_micron(&self) -> Self
Convert to LengthUnit::micron
.
Sourcepub fn to_mil(&self) -> Self
pub fn to_mil(&self) -> Self
Convert to LengthUnit::mil
.
Sourcepub fn to_mile(&self) -> Self
pub fn to_mile(&self) -> Self
Convert to LengthUnit::mile
.
Sourcepub fn to_mile_survey(&self) -> Self
pub fn to_mile_survey(&self) -> Self
Convert to LengthUnit::mile_survey
.
Sourcepub fn to_nautical_mile(&self) -> Self
pub fn to_nautical_mile(&self) -> Self
Convert to LengthUnit::nautical_mile
.
Sourcepub fn to_parsec(&self) -> Self
pub fn to_parsec(&self) -> Self
Convert to LengthUnit::parsec
.
Sourcepub fn to_pica_computer(&self) -> Self
pub fn to_pica_computer(&self) -> Self
Convert to LengthUnit::pica_computer
.
Sourcepub fn to_pica_printers(&self) -> Self
pub fn to_pica_printers(&self) -> Self
Convert to LengthUnit::pica_printers
.
Sourcepub fn to_point_computer(&self) -> Self
pub fn to_point_computer(&self) -> Self
Convert to LengthUnit::point_computer
.
Sourcepub fn to_point_printers(&self) -> Self
pub fn to_point_printers(&self) -> Self
Convert to LengthUnit::point_printers
.
Sourcepub fn to_rod(&self) -> Self
pub fn to_rod(&self) -> Self
Convert to LengthUnit::rod
.
Sourcepub fn to_yard(&self) -> Self
pub fn to_yard(&self) -> Self
Convert to LengthUnit::yard
.
pub fn at(&self, index: usize) -> Length
Methods from Deref<Target = [f64; N]>§
1.57.0 · Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns a slice containing the entire array. Equivalent to &s[..]
.
1.57.0 · Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns a mutable slice containing the entire array. Equivalent to
&mut s[..]
.
1.77.0 · Sourcepub fn each_ref(&self) -> [&T; N]
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 · Sourcepub fn each_mut(&mut self) -> [&mut T; N]
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]);
Sourcepub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
🔬This is a nightly-only experimental API. (split_array
)
pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
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, &[]);
}
Sourcepub fn split_array_mut<const M: usize>(&mut self) -> (&mut [T; M], &mut [T])
🔬This is a nightly-only experimental API. (split_array
)
pub fn split_array_mut<const M: usize>(&mut self) -> (&mut [T; M], &mut [T])
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]);
Sourcepub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
🔬This is a nightly-only experimental API. (split_array
)
pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
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]);
}
Sourcepub fn rsplit_array_mut<const M: usize>(&mut self) -> (&mut [T], &mut [T; M])
🔬This is a nightly-only experimental API. (split_array
)
pub fn rsplit_array_mut<const M: usize>(&mut self) -> (&mut [T], &mut [T; M])
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>
impl<const N: usize> Add for LengthArray<N>
Source§type Output = LengthArray<N>
type Output = LengthArray<N>
+
operator.Source§fn add(self, rhs: LengthArray<N>) -> Self
fn add(self, rhs: LengthArray<N>) -> Self
+
operation. Read moreSource§impl<const N: usize> AddAssign for LengthArray<N>
impl<const N: usize> AddAssign for LengthArray<N>
Source§fn add_assign(&mut self, rhs: LengthArray<N>)
fn add_assign(&mut self, rhs: LengthArray<N>)
+=
operation. Read moreSource§impl<const N: usize> Clone for LengthArray<N>
impl<const N: usize> Clone for LengthArray<N>
Source§fn clone(&self) -> LengthArray<N>
fn clone(&self) -> LengthArray<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<const N: usize> Debug for LengthArray<N>
impl<const N: usize> Debug for LengthArray<N>
Source§impl<const N: usize> Default for LengthArray<N>
impl<const N: usize> Default for LengthArray<N>
Source§impl<const N: usize> Deref for LengthArray<N>
impl<const N: usize> Deref for LengthArray<N>
Source§impl<const N: usize> DerefMut for LengthArray<N>
impl<const N: usize> DerefMut for LengthArray<N>
Source§impl<const N: usize> DivAssign<f64> for LengthArray<N>
impl<const N: usize> DivAssign<f64> for LengthArray<N>
Source§fn div_assign(&mut self, rhs: f64)
fn div_assign(&mut self, rhs: f64)
/=
operation. Read moreSource§impl<const N: usize> FixedSliceQuantity<LengthUnit, f64> for LengthArray<N>
impl<const N: usize> FixedSliceQuantity<LengthUnit, f64> for LengthArray<N>
Source§fn unit(&self) -> LengthUnit
fn unit(&self) -> LengthUnit
Source§fn values_mut(&mut self) -> &mut [f64]
fn values_mut(&mut self) -> &mut [f64]
Source§fn convert(&self, unit: LengthUnit) -> Self
fn convert(&self, unit: LengthUnit) -> Self
UnitType
to another of the same type. No validation of base unit is made.Source§fn convert_mut(&mut self, unit: LengthUnit)
fn convert_mut(&mut self, unit: LengthUnit)
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,
fn try_convert(&self, unit: Units) -> Result<Self, RuntimeUnitError>where
Self: Sized,
unit
to a UnitType
. Base unit validation is made here.Source§impl<const N: usize> MulAssign<f64> for LengthArray<N>
impl<const N: usize> MulAssign<f64> for LengthArray<N>
Source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
*=
operation. Read moreSource§impl<const N: usize> PartialEq for LengthArray<N>
impl<const N: usize> PartialEq for LengthArray<N>
Source§impl<const N: usize> Sub for LengthArray<N>
impl<const N: usize> Sub for LengthArray<N>
Source§type Output = LengthArray<N>
type Output = LengthArray<N>
-
operator.Source§fn sub(self, rhs: LengthArray<N>) -> Self
fn sub(self, rhs: LengthArray<N>) -> Self
-
operation. Read moreSource§impl<const N: usize> SubAssign for LengthArray<N>
impl<const N: usize> SubAssign for LengthArray<N>
Source§fn sub_assign(&mut self, rhs: LengthArray<N>)
fn sub_assign(&mut self, rhs: LengthArray<N>)
-=
operation. Read more