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§
Sourcefn signed_digit_count(&self, base: u64) -> i64
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§
Sourcefn signed_width(&self) -> u64
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);
Sourcefn signed_width_base(&self, base: u64) -> u64
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);
Sourcefn width(&self) -> u64
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);
Sourcefn width_base(&self, base: u64) -> u64
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.