pub trait Unit: Sized {
const BASE: Option<i32> = None;
Show 18 methods
// Required methods
fn symbol(&self) -> &str ⓘ;
fn symbol_ascii(&self) -> &str ⓘ;
fn name(&self) -> &str ⓘ;
fn factor(&self) -> f64 ⓘ;
fn factor_i64(&self) -> i64 ⓘ;
fn factor_i128(&self) -> i128 ⓘ;
fn asc_iter() -> impl Iterator<Item = Self>;
fn desc_iter() -> impl Iterator<Item = Self>;
fn convert(value: f64, from: Self, to: Self) -> f64 ⓘ;
fn convert_i64(value: i64, from: Self, to: Self) -> (i64, i64) ⓘ;
fn convert_i128(value: i128, from: Self, to: Self) -> (i128, i128) ⓘ;
fn reduce(value: f64) -> (f64, Self) ⓘ;
fn reduce_i64(value: i64) -> (i64, Self, i64) ⓘ;
fn reduce_i128(value: i128) -> (i128, Self, i128) ⓘ;
fn reduce_chain(value: f64, threshold: f64) -> Vec<(f64, Self)> ⓘ;
fn reduce_chain_i64(value: i64, threshold: i64) -> Vec<(i64, Self)> ⓘ;
fn reduce_chain_i128(value: i128, threshold: i128) -> Vec<(i128, Self)> ⓘ;
// Provided method
fn exp(&self) -> Option<i32> ⓘ { ... }
}
unit
only.Expand description
Unit prefixes.
Provided Associated Constants§
Required Methods§
Sourcefn symbol_ascii(&self) -> &str ⓘ
fn symbol_ascii(&self) -> &str ⓘ
Returns the ASCII symbol of the prefix.
Sourcefn factor_i64(&self) -> i64 ⓘ
fn factor_i64(&self) -> i64 ⓘ
Returns the multiplication factor for the prefix as an i64.
Sourcefn factor_i128(&self) -> i128 ⓘ
fn factor_i128(&self) -> i128 ⓘ
Returns the multiplication factor for the prefix as an i128.
Sourcefn asc_iter() -> impl Iterator<Item = Self>
fn asc_iter() -> impl Iterator<Item = Self>
Returns an iterator in ascending order of magnitude.
Sourcefn desc_iter() -> impl Iterator<Item = Self>
fn desc_iter() -> impl Iterator<Item = Self>
Returns an iterator in descending order of magnitude.
Sourcefn convert(value: f64, from: Self, to: Self) -> f64 ⓘ
fn convert(value: f64, from: Self, to: Self) -> f64 ⓘ
Converts a value from one unit prefix variant to another, returning the converted value.
Sourcefn convert_i64(value: i64, from: Self, to: Self) -> (i64, i64) ⓘ
fn convert_i64(value: i64, from: Self, to: Self) -> (i64, i64) ⓘ
Converts a value from one prefix to another, returning the converted value and the remainder.
Sourcefn convert_i128(value: i128, from: Self, to: Self) -> (i128, i128) ⓘ
fn convert_i128(value: i128, from: Self, to: Self) -> (i128, i128) ⓘ
Converts a value from one prefix to another, returning the converted value and the remainder.
Sourcefn reduce(value: f64) -> (f64, Self) ⓘ
fn reduce(value: f64) -> (f64, Self) ⓘ
Reduces the given value
to the most appropriate prefix as a f64,
returning a tuple of the reduced size and the prefix.
The input value
is assumed to be non-negative, and in base units,
meaning it has no prefix applied.
This method simplifies large numerical values by scaling them down to the largest appropriate prefix (e.g., Kibi, Mebi, Gibi, etc.).
Sourcefn reduce_i64(value: i64) -> (i64, Self, i64) ⓘ
fn reduce_i64(value: i64) -> (i64, Self, i64) ⓘ
Reduces the given value to the most appropriate prefix as a i64, returning a tuple of the reduced size, the prefix, and the remainder.
The input value
is assumed to be non-negative, and in base units,
meaning it has no prefix applied.
This method simplifies large numerical values by scaling them down to the largest appropriate prefix (e.g., Kibi, Mebi, Gibi, etc.).
Sourcefn reduce_i128(value: i128) -> (i128, Self, i128) ⓘ
fn reduce_i128(value: i128) -> (i128, Self, i128) ⓘ
Reduces the given value to the most appropriate prefix as a i128, returning a tuple of the reduced size, the prefix, and the remainder.
The input value
is assumed to be non-negative, and in base units,
meaning it has no prefix applied.
This method simplifies large numerical values by scaling them down to the largest appropriate prefix (e.g., Kibi, Mebi, Gibi, etc.).
Sourcefn reduce_chain(value: f64, threshold: f64) -> Vec<(f64, Self)> ⓘ
fn reduce_chain(value: f64, threshold: f64) -> Vec<(f64, Self)> ⓘ
Reduces the given value to a chain of appropriate prefixes as f64, stopping when the remainder is less than the given threshold.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.