Type Definition dactyl::NiceU8

source ·
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>
  • Clone
  • Copy
  • Default
  • Deref<Target=[u8]>
  • Display
  • Eq / PartialEq
  • Hash
  • Ord / 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.

Implementations§

source§

impl NiceU8

source

pub 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");
source

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");
source

pub 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");
source

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");

Trait Implementations§

source§

impl Default for NiceU8

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<NonZeroU8> for NiceU8

source§

fn from(num: NonZeroU8) -> Self

Converts to this type from the input type.
source§

impl From<u8> for NiceU8

source§

fn from(num: u8) -> Self

Converts to this type from the input type.