Skip to main content

EngineeringRepr

Trait EngineeringRepr 

Source
pub trait EngineeringRepr<T: EQSupported<T>> {
    // Required methods
    fn to_eng(self, sig_figures: usize) -> DisplayAdapter<T>;
    fn to_rkm(self, sig_figures: usize) -> DisplayAdapter<T>;
}
Expand description

A convenience trait for outputting integers directly in engineering notation.

DisplayAdapter implements Display, so you can use the returned adapter directly in a formatting macro.

Required Methods§

Source

fn to_eng(self, sig_figures: usize) -> DisplayAdapter<T>

Outputs a number in engineering notation

A request for 0 significant figures outputs exactly as many digits are necessary to maintain precision.

use engineering_repr::EngineeringRepr as _;
assert_eq!("123k", 123456.to_eng(3));
assert_eq!("123.4k", 123456.to_eng(4));
assert_eq!("123.456k", 123456.to_eng(0));
§Panics

If the value could not be rendered

Source

fn to_rkm(self, sig_figures: usize) -> DisplayAdapter<T>

Outputs a number in RKM notation

A request for 0 significant figures outputs exactly as many digits are necessary to maintain precision.

use engineering_repr::EngineeringRepr as _;
assert_eq!("123k", 123456.to_rkm(3));
assert_eq!("123k4", 123456.to_rkm(4));
assert_eq!("123k456", 123456.to_rkm(0));
§Panics

If the value could not be rendered

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl EngineeringRepr<i16> for i16

Source§

fn to_eng(self, sig_figures: usize) -> DisplayAdapter<i16>

Source§

fn to_rkm(self, sig_figures: usize) -> DisplayAdapter<i16>

Source§

impl EngineeringRepr<i32> for i32

Source§

fn to_eng(self, sig_figures: usize) -> DisplayAdapter<i32>

Source§

fn to_rkm(self, sig_figures: usize) -> DisplayAdapter<i32>

Source§

impl EngineeringRepr<i64> for i64

Source§

fn to_eng(self, sig_figures: usize) -> DisplayAdapter<i64>

Source§

fn to_rkm(self, sig_figures: usize) -> DisplayAdapter<i64>

Source§

impl EngineeringRepr<i128> for i128

Source§

fn to_eng(self, sig_figures: usize) -> DisplayAdapter<i128>

Source§

fn to_rkm(self, sig_figures: usize) -> DisplayAdapter<i128>

Source§

impl EngineeringRepr<isize> for isize

Source§

fn to_eng(self, sig_figures: usize) -> DisplayAdapter<isize>

Source§

fn to_rkm(self, sig_figures: usize) -> DisplayAdapter<isize>

Source§

impl EngineeringRepr<u16> for u16

Source§

fn to_eng(self, sig_figures: usize) -> DisplayAdapter<u16>

Source§

fn to_rkm(self, sig_figures: usize) -> DisplayAdapter<u16>

Source§

impl EngineeringRepr<u32> for u32

Source§

fn to_eng(self, sig_figures: usize) -> DisplayAdapter<u32>

Source§

fn to_rkm(self, sig_figures: usize) -> DisplayAdapter<u32>

Source§

impl EngineeringRepr<u64> for u64

Source§

fn to_eng(self, sig_figures: usize) -> DisplayAdapter<u64>

Source§

fn to_rkm(self, sig_figures: usize) -> DisplayAdapter<u64>

Source§

impl EngineeringRepr<u128> for u128

Source§

fn to_eng(self, sig_figures: usize) -> DisplayAdapter<u128>

Source§

fn to_rkm(self, sig_figures: usize) -> DisplayAdapter<u128>

Source§

impl EngineeringRepr<usize> for usize

Source§

fn to_eng(self, sig_figures: usize) -> DisplayAdapter<usize>

Source§

fn to_rkm(self, sig_figures: usize) -> DisplayAdapter<usize>

Implementors§