pub type NiceU16 = NiceWrapper<SIZE>;Expand description
NiceU16 provides a quick way to convert a u16 into a formatted byte
string for e.g. printing. Commas are added for every thousand.
That’s it!
Examples
use dactyl::NiceU16;
assert_eq!(
NiceU16::from(33231).as_str(),
"33,231"
);Traits
Rustdoc doesn’t do a good job at documenting type alias implementations, but
NiceU16 has a bunch, including:
AsRef<[u8]>AsRef<str>Borrow<[u8]>Borrow<str>CloneCopyDefaultDeref<Target=[u8]>DisplayEq/PartialEqHashOrd/PartialOrd
You can instantiate a NiceU16 with:
From<u16>From<Option<u16>>From<NonZeroU16>From<Option<NonZeroU16>>
When converting from a None, the result will be equivalent to zero.
Implementations§
source§impl NiceU16
impl NiceU16
sourcepub fn with_separator(num: u16, sep: u8) -> Self
pub fn with_separator(num: u16, 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 [NiceU16::from] instead.
Examples
use dactyl::NiceU16;
let num = NiceU16::from(31415_u16);
assert_eq!(num.as_str(), "31,415");
let num = NiceU16::with_separator(31415_u16, b'_');
assert_eq!(num.as_str(), "31_415");Panics
This method will panic if the separator is invalid ASCII.