pub type NiceU8 = NiceWrapper<SIZE>;Expand description
NiceU8 provides a quick way to convert a u8 into a formatted byte
string for e.g. printing.
That’s it!
§Examples
use dactyl::NiceU8;
assert_eq!(
NiceU8::from(231).as_str(),
"231"
);§Traits
Rustdoc doesn’t do a good job at documenting type alias implementations, but
NiceU8 has a bunch, including:
AsRef<[u8]>AsRef<str>Borrow<[u8]>Borrow<str>CloneCopyDefaultDeref<Target=[u8]>DisplayEq/PartialEqHashOrd/PartialOrd
You can instantiate a NiceU8 with:
From<u8>From<Option<u8>>From<NonZeroU8>From<Option<NonZeroU8>>
When converting from a None, the result will be equivalent to zero.
Aliased Type§
struct NiceU8 { /* private fields */ }Implementations§
Source§impl NiceU8
impl NiceU8
Source§impl NiceU8
impl NiceU8
Sourcepub const fn as_bytes2(&self) -> &[u8] ⓘ
pub const fn as_bytes2(&self) -> &[u8] ⓘ
§Double Digit Bytes.
This method will return return a byte slice that is at least two bytes long, left padding the value with a zero if its natural length is shorter. (In other words, this has no effect if the value is >= 10.)
§Examples
assert_eq!(dactyl::NiceU8::from(3).as_bytes2(), b"03");
assert_eq!(dactyl::NiceU8::from(50).as_bytes2(), b"50");
assert_eq!(dactyl::NiceU8::from(113).as_bytes2(), b"113");Sourcepub const fn as_bytes3(&self) -> &[u8] ⓘ
pub const fn as_bytes3(&self) -> &[u8] ⓘ
§Triple Digit Bytes.
This method will return return a byte slice that is at least three bytes long, left padding the value with a zero if its natural length is shorter. (In other words, this has no effect if the value is >= 100.)
§Examples
assert_eq!(dactyl::NiceU8::from(3).as_bytes3(), b"003");
assert_eq!(dactyl::NiceU8::from(50).as_bytes3(), b"050");
assert_eq!(dactyl::NiceU8::from(113).as_bytes3(), b"113");Sourcepub const fn as_str2(&self) -> &str
pub const fn as_str2(&self) -> &str
§Double Digit Str.
This method will return return a string slice that is at least two chars long, left padding the value with a zero if its natural length is shorter. (In other words, this has no effect if the value is >= 10.)
§Examples
assert_eq!(dactyl::NiceU8::from(3).as_str2(), "03");
assert_eq!(dactyl::NiceU8::from(50).as_str2(), "50");
assert_eq!(dactyl::NiceU8::from(113).as_str2(), "113");Sourcepub const fn as_str3(&self) -> &str
pub const fn as_str3(&self) -> &str
§Triple Digit Str.
This method will return return a string slice that is at least three chars long, left padding the value with zeroes if its natural length is shorter. (In other words, this has no effect if the value is >= 100.)
§Examples
assert_eq!(dactyl::NiceU8::from(3).as_str3(), "003");
assert_eq!(dactyl::NiceU8::from(50).as_str3(), "050");
assert_eq!(dactyl::NiceU8::from(113).as_str3(), "113");