Struct dactyl::NiceU8[][src]

pub struct NiceU8 { /* fields omitted */ }
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"
);

Implementations

Casting.

This section provides methods for converting instances into other types.

Note: this struct can also be dereferenced to &[u8].

As Bytes.

Return the value as a byte string.

As Str.

Return the value as a string slice.

Min.

This is equivalent to zero.

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

Performs the conversion.

Performs the conversion.

Immutably borrows from an owned value. Read more

Immutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

The resulting type after dereferencing.

Dereferences the value.

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.