pub type NiceU64 = NiceWrapper<SIZE>;Expand description
NiceU64 provides a quick way to convert a u64 into a formatted byte
string for e.g. printing. Commas are added for every thousand.
That’s it!
§Examples
use dactyl::NiceU64;
assert_eq!(
NiceU64::from(33231_u64).as_str(),
"33,231"
);§Traits
Rustdoc doesn’t do a good job at documenting type alias implementations, but
NiceU64 has a bunch, including:
AsRef<[u8]>AsRef<str>Borrow<[u8]>Borrow<str>CloneCopyDefaultDeref<Target=[u8]>DisplayEq/PartialEqHashOrd/PartialOrd
You can instantiate a NiceU64 with:
From<u64>From<Option<u64>>From<NonZeroU64>From<Option<NonZeroU64>>From<usize>From<Option<usize>>From<NonZeroUsize>From<Option<NonZeroUsize>>
When converting from a None, the result will be equivalent to zero.
For targets with 128-bit pointers, usize values cannot exceed u64::MAX
or a panic will ensue.
Aliased Type§
struct NiceU64 { /* private fields */ }Implementations§
Source§impl NiceU64
impl NiceU64
Source§impl NiceU64
impl NiceU64
Sourcepub fn with_separator(num: u64, sep: u8) -> Self
pub fn with_separator(num: u64, sep: u8) -> Self
§New Instance w/ Custom Separator.
Create a new instance, defining any arbitrary ASCII byte as the thousands separator.
If you’re good with commas, just use [NiceU64::from] instead.
§Examples
use dactyl::NiceU64;
let num = NiceU64::from(3141592653589793238_u64);
assert_eq!(num.as_str(), "3,141,592,653,589,793,238");
let num = NiceU64::with_separator(3141592653589793238_u64, b'_');
assert_eq!(num.as_str(), "3_141_592_653_589_793_238");§Panics
This method will panic if the separator is invalid ASCII.
Sourcepub fn replace(&mut self, num: u64)
pub fn replace(&mut self, num: u64)
§Replace.
Reuse the backing storage behind self to hold a new nice number.
§Examples.
use dactyl::NiceU64;
let mut num = NiceU64::from(3141592653_u64);
assert_eq!(num.as_str(), "3,141,592,653");
num.replace(12345);
assert_eq!(num.as_str(), "12,345");Note that custom separators, if any, are preserved.
use dactyl::NiceU64;
let mut num = NiceU64::with_separator(3141592653_u64, b'_');
assert_eq!(num.as_str(), "3_141_592_653");
num.replace(12345);
assert_eq!(num.as_str(), "12_345");