pub struct MassArray<const N: usize> { /* private fields */ }Expand description
Array storage for a series of values and MassUnit.
Implementations§
Source§impl<const D: usize> MassArray<D>
impl<const D: usize> MassArray<D>
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 [MassSlice].
Sourcepub fn yottagram(values: [f64; D]) -> Self
pub fn yottagram(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::yottagram.
Sourcepub fn zettagram(values: [f64; D]) -> Self
pub fn zettagram(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::zettagram.
Sourcepub fn hectogram(values: [f64; D]) -> Self
pub fn hectogram(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::hectogram.
Sourcepub fn centigram(values: [f64; D]) -> Self
pub fn centigram(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::centigram.
Sourcepub fn milligram(values: [f64; D]) -> Self
pub fn milligram(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::milligram.
Sourcepub fn microgram(values: [f64; D]) -> Self
pub fn microgram(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::microgram.
Sourcepub fn femtogram(values: [f64; D]) -> Self
pub fn femtogram(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::femtogram.
Sourcepub fn zeptogram(values: [f64; D]) -> Self
pub fn zeptogram(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::zeptogram.
Sourcepub fn yoctogram(values: [f64; D]) -> Self
pub fn yoctogram(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::yoctogram.
Sourcepub fn hundredweight_long(values: [f64; D]) -> Self
pub fn hundredweight_long(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::hundredweight_long.
Sourcepub fn hundredweight_short(values: [f64; D]) -> Self
pub fn hundredweight_short(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::hundredweight_short.
Sourcepub fn ounce_troy(values: [f64; D]) -> Self
pub fn ounce_troy(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::ounce_troy.
Sourcepub fn pennyweight(values: [f64; D]) -> Self
pub fn pennyweight(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::pennyweight.
Sourcepub fn pound_troy(values: [f64; D]) -> Self
pub fn pound_troy(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::pound_troy.
Sourcepub fn ton_assay(values: [f64; D]) -> Self
pub fn ton_assay(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::ton_assay.
Sourcepub fn ton_short(values: [f64; D]) -> Self
pub fn ton_short(values: [f64; D]) -> Self
Create a new Mass with units of MassUnit::ton_short.
Sourcepub fn to_yottagram(&self) -> Self
pub fn to_yottagram(&self) -> Self
Convert to MassUnit::yottagram.
Sourcepub fn to_zettagram(&self) -> Self
pub fn to_zettagram(&self) -> Self
Convert to MassUnit::zettagram.
Sourcepub fn to_exagram(&self) -> Self
pub fn to_exagram(&self) -> Self
Convert to MassUnit::exagram.
Sourcepub fn to_petagram(&self) -> Self
pub fn to_petagram(&self) -> Self
Convert to MassUnit::petagram.
Sourcepub fn to_teragram(&self) -> Self
pub fn to_teragram(&self) -> Self
Convert to MassUnit::teragram.
Sourcepub fn to_gigagram(&self) -> Self
pub fn to_gigagram(&self) -> Self
Convert to MassUnit::gigagram.
Sourcepub fn to_megagram(&self) -> Self
pub fn to_megagram(&self) -> Self
Convert to MassUnit::megagram.
Sourcepub fn to_kilogram(&self) -> Self
pub fn to_kilogram(&self) -> Self
Convert to MassUnit::kilogram.
Sourcepub fn to_hectogram(&self) -> Self
pub fn to_hectogram(&self) -> Self
Convert to MassUnit::hectogram.
Sourcepub fn to_decagram(&self) -> Self
pub fn to_decagram(&self) -> Self
Convert to MassUnit::decagram.
Sourcepub fn to_gram(&self) -> Self
pub fn to_gram(&self) -> Self
Convert to MassUnit::gram.
Sourcepub fn to_decigram(&self) -> Self
pub fn to_decigram(&self) -> Self
Convert to MassUnit::decigram.
Sourcepub fn to_centigram(&self) -> Self
pub fn to_centigram(&self) -> Self
Convert to MassUnit::centigram.
Sourcepub fn to_milligram(&self) -> Self
pub fn to_milligram(&self) -> Self
Convert to MassUnit::milligram.
Sourcepub fn to_microgram(&self) -> Self
pub fn to_microgram(&self) -> Self
Convert to MassUnit::microgram.
Sourcepub fn to_nanogram(&self) -> Self
pub fn to_nanogram(&self) -> Self
Convert to MassUnit::nanogram.
Sourcepub fn to_picogram(&self) -> Self
pub fn to_picogram(&self) -> Self
Convert to MassUnit::picogram.
Sourcepub fn to_femtogram(&self) -> Self
pub fn to_femtogram(&self) -> Self
Convert to MassUnit::femtogram.
Sourcepub fn to_attogram(&self) -> Self
pub fn to_attogram(&self) -> Self
Convert to MassUnit::attogram.
Sourcepub fn to_zeptogram(&self) -> Self
pub fn to_zeptogram(&self) -> Self
Convert to MassUnit::zeptogram.
Sourcepub fn to_yoctogram(&self) -> Self
pub fn to_yoctogram(&self) -> Self
Convert to MassUnit::yoctogram.
Sourcepub fn to_carat(&self) -> Self
pub fn to_carat(&self) -> Self
Convert to MassUnit::carat.
Sourcepub fn to_dalton(&self) -> Self
pub fn to_dalton(&self) -> Self
Convert to MassUnit::dalton.
Sourcepub fn to_grain(&self) -> Self
pub fn to_grain(&self) -> Self
Convert to MassUnit::grain.
Sourcepub fn to_hundredweight_long(&self) -> Self
pub fn to_hundredweight_long(&self) -> Self
Convert to MassUnit::hundredweight_long.
Sourcepub fn to_hundredweight_short(&self) -> Self
pub fn to_hundredweight_short(&self) -> Self
Convert to MassUnit::hundredweight_short.
Sourcepub fn to_ounce(&self) -> Self
pub fn to_ounce(&self) -> Self
Convert to MassUnit::ounce.
Sourcepub fn to_ounce_troy(&self) -> Self
pub fn to_ounce_troy(&self) -> Self
Convert to MassUnit::ounce_troy.
Sourcepub fn to_pennyweight(&self) -> Self
pub fn to_pennyweight(&self) -> Self
Convert to MassUnit::pennyweight.
Sourcepub fn to_pound(&self) -> Self
pub fn to_pound(&self) -> Self
Convert to MassUnit::pound.
Sourcepub fn to_pound_troy(&self) -> Self
pub fn to_pound_troy(&self) -> Self
Convert to MassUnit::pound_troy.
Sourcepub fn to_slug(&self) -> Self
pub fn to_slug(&self) -> Self
Convert to MassUnit::slug.
Sourcepub fn to_ton_assay(&self) -> Self
pub fn to_ton_assay(&self) -> Self
Convert to MassUnit::ton_assay.
Sourcepub fn to_ton_long(&self) -> Self
pub fn to_ton_long(&self) -> Self
Convert to MassUnit::ton_long.
Sourcepub fn to_ton_short(&self) -> Self
pub fn to_ton_short(&self) -> Self
Convert to MassUnit::ton_short.
Sourcepub fn to_ton(&self) -> Self
pub fn to_ton(&self) -> Self
Convert to MassUnit::ton.
pub fn at(&self, index: usize) -> Mass
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> AddAssign for MassArray<N>
impl<const N: usize> AddAssign for MassArray<N>
Source§fn add_assign(&mut self, rhs: MassArray<N>)
fn add_assign(&mut self, rhs: MassArray<N>)
+= operation. Read moreSource§impl<const N: usize> DivAssign<f64> for MassArray<N>
impl<const N: usize> DivAssign<f64> for MassArray<N>
Source§fn div_assign(&mut self, rhs: f64)
fn div_assign(&mut self, rhs: f64)
/= operation. Read moreSource§impl<const N: usize> FixedSliceQuantity<MassUnit, f64> for MassArray<N>
impl<const N: usize> FixedSliceQuantity<MassUnit, f64> for MassArray<N>
Source§fn values_mut(&mut self) -> &mut [f64]
fn values_mut(&mut self) -> &mut [f64]
Source§fn convert(&self, unit: MassUnit) -> Self
fn convert(&self, unit: MassUnit) -> Self
UnitType to another of the same type. No validation of base unit is made.Source§fn convert_mut(&mut self, unit: MassUnit)
fn convert_mut(&mut self, unit: MassUnit)
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 MassArray<N>
impl<const N: usize> MulAssign<f64> for MassArray<N>
Source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
*= operation. Read moreSource§impl<const N: usize> SubAssign for MassArray<N>
impl<const N: usize> SubAssign for MassArray<N>
Source§fn sub_assign(&mut self, rhs: MassArray<N>)
fn sub_assign(&mut self, rhs: MassArray<N>)
-= operation. Read more