devela::num

Trait Unit

Source
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> { ... }
}
Available on crate feature unit only.
Expand description

Provided Associated Constants§

Source

const BASE: Option<i32> = None

The base value for unit prefixes.

Required Methods§

Source

fn symbol(&self) -> &str

Returns the symbol of the prefix.

Source

fn symbol_ascii(&self) -> &str

Returns the ASCII symbol of the prefix.

Source

fn name(&self) -> &str

Returns the name of the prefix.

Source

fn factor(&self) -> f64

Returns the multiplication factor for the prefix as an f64.

Source

fn factor_i64(&self) -> i64

Returns the multiplication factor for the prefix as an i64.

Source

fn factor_i128(&self) -> i128

Returns the multiplication factor for the prefix as an i128.

Source

fn asc_iter() -> impl Iterator<Item = Self>

Returns an iterator in ascending order of magnitude.

Source

fn desc_iter() -> impl Iterator<Item = Self>

Returns an iterator in descending order of magnitude.

Source

fn convert(value: f64, from: Self, to: Self) -> f64

Converts a value from one unit prefix variant to another, returning the converted value.

Source

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.

Source

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.

Source

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.).

Source

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.).

Source

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.).

Source

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.

Source

fn reduce_chain_i64(value: i64, threshold: i64) -> Vec<(i64, Self)>

Reduces the given value to a chain of appropriate prefixes as i64, stopping when the remainder is less than the given threshold.

Source

fn reduce_chain_i128(value: i128, threshold: i128) -> Vec<(i128, Self)>

Reduces the given value to a chain of appropriate prefixes as i128, stopping when the remainder is less than the given threshold.

Provided Methods§

Source

fn exp(&self) -> Option<i32>

Returns the exponent corresponding to the unit prefix.

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.

Implementors§