Trait NumberWidth

Source
pub trait NumberWidth {
    // Required method
    fn signed_digit_count(&self, base: u64) -> i64;

    // Provided methods
    fn signed_width(&self) -> u64 { ... }
    fn signed_width_base(&self, base: u64) -> u64 { ... }
    fn width(&self) -> u64 { ... }
    fn width_base(&self, base: u64) -> u64 { ... }
}
Expand description

Determine the width needed to display a number.

Required Methods§

Source

fn signed_digit_count(&self, base: u64) -> i64

Digit count in the given base.

This is expected to be zero for the number zero, and negative for negative numbers.

Provided Methods§

Source

fn signed_width(&self) -> u64

Width including leading minus sign if the number is negative.

§Example
use num_width::NumberWidth;
assert_eq!(0u8.signed_width(), 1);
assert_eq!(15u8.signed_width(), 2);
assert_eq!((-33i8).signed_width(), 3);
Source

fn signed_width_base(&self, base: u64) -> u64

Width of the number in the given base, including leading minus sign for negative numbers.

§Example
use num_width::NumberWidth;
assert_eq!(0xAu8.signed_width_base(16), 1);
assert_eq!(0xFFu8.signed_width_base(16), 2);
assert_eq!((-0xAAi16).signed_width_base(16), 3);
Source

fn width(&self) -> u64

Width needed to represent number.

This does not include the width needed for a leading minus sign in case the number is negative. If that is what you need, consider using the [signed_width()][] method.

§Example
use num_width::NumberWidth;
assert_eq!(0u8.width(), 1);
assert_eq!(15u8.width(), 2);
assert_eq!((-33i8).width(), 2);
Source

fn width_base(&self, base: u64) -> u64

Width needed to represent number in the given base.

This does not include the width needed for a leading minus sign in case the number is negative. If that is what you need, consider using the [signed_width_base()][] method.

Implementations on Foreign Types§

Source§

impl NumberWidth for i8

Source§

fn signed_digit_count(&self, base: u64) -> i64

Source§

impl NumberWidth for i16

Source§

fn signed_digit_count(&self, base: u64) -> i64

Source§

impl NumberWidth for i32

Source§

fn signed_digit_count(&self, base: u64) -> i64

Source§

impl NumberWidth for i64

Source§

fn signed_digit_count(&self, base: u64) -> i64

Source§

impl NumberWidth for u8

Source§

fn signed_digit_count(&self, base: u64) -> i64

Source§

impl NumberWidth for u16

Source§

fn signed_digit_count(&self, base: u64) -> i64

Source§

impl NumberWidth for u32

Source§

fn signed_digit_count(&self, base: u64) -> i64

Source§

impl NumberWidth for u64

Source§

fn signed_digit_count(&self, base: u64) -> i64

Implementors§