NiceU32

Struct NiceU32 

Source
pub struct NiceU32 { /* private fields */ }
Expand description

§Nice u32.

This struct can be used to quickly and efficiently stringify a u32 primitive (with thousands separators).

§Examples

use dactyl::NiceU32;

assert_eq!(
    NiceU32::from(u32::MAX).as_str(),
    "4,294,967,295",
);

Implementations§

Source§

impl NiceU32

Source

pub const fn as_bytes(&self) -> &[u8]

§As Byte Slice.

Return the value as a byte slice.

§Examples
use dactyl::NiceU32;

assert_eq!(
    NiceU32::from(u32::MAX).as_bytes(),
    b"4,294,967,295",
);
Source

pub const fn as_str(&self) -> &str

§As String Slice.

Return the value as a string slice.

§Examples
use dactyl::NiceU32;

assert_eq!(
    NiceU32::from(u32::MAX).as_str(),
    "4,294,967,295",
);
Source

pub const fn is_empty(&self) -> bool

§Is Empty?

No! Haha. But for consistency, this method exists.

Source

pub const fn len(&self) -> usize

§Length.

Return the length of the nice byte/string representation.

Note this will never be zero.

§Examples
use dactyl::NiceU32;

let nice = NiceU32::MAX;
assert_eq!(
    nice.len(),
    nice.as_str().len(),
);
Source§

impl NiceU32

Source

pub const MIN: Self

§Minimum Value.

The nice equivalent of u32::MIN.

§Examples
use dactyl::NiceU32;

assert_eq!(
    NiceU32::MIN.as_str(),
    "0",
);
Source

pub const MAX: Self

§Maximum Value.

The nice equivalent of u32::MAX.

§Examples
use dactyl::NiceU32;

assert_eq!(
    NiceU32::MAX.as_str(),
    "4,294,967,295",
);
Source§

impl NiceU32

Source

pub fn with_separator(src: u32, sep: NiceSeparator) -> Self

§New (w/ Alternative Thousands Separator).

Nicely stringify a u32 with a specific thousands separator (instead of the default comma).

§Examples
use dactyl::{NiceSeparator, NiceU32};

let num: u32 = 54321;

// Commas are used by default.
assert_eq!(
    NiceU32::from(num).as_str(),
    "54,321",
);

// Other contexts might prefer, say, underscores…
assert_eq!(
    NiceU32::with_separator(
        num,
        NiceSeparator::Underscore,
    ).as_str(),
    "54_321",
);
Source

pub fn replace(&mut self, src: u32)

§Replace w/ New Number.

Reuse the backing storage behind self to hold a new nice number.

§Examples.
use dactyl::NiceU32;

let mut num = NiceU32::from(1234_u32);
assert_eq!(num.as_str(), "1,234");

num.replace(1);
assert_eq!(num.as_str(), "1");

Trait Implementations§

Source§

impl AsRef<[u8]> for NiceU32

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<str> for NiceU32

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<str> for NiceU32

Source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl Clone for NiceU32

Source§

fn clone(&self) -> NiceU32

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NiceU32

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NiceU32

Source§

fn default() -> Self

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

impl Display for NiceU32

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<NiceU32> for String

Source§

fn from(src: NiceU32) -> Self

Converts to this type from the input type.
Source§

impl From<NonZero<u32>> for NiceU32

Source§

fn from(src: NonZeroU32) -> Self

Converts to this type from the input type.
Source§

impl From<Option<NonZero<u32>>> for NiceU32

Source§

fn from(src: Option<NonZeroU32>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<u32>> for NiceU32

Source§

fn from(src: Option<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for NiceU32

Source§

fn from(src: u32) -> Self

Converts to this type from the input type.
Source§

impl Hash for NiceU32

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<T: Inflection> NiceInflection<NiceU32> for T
where NiceU32: From<T>,

Source§

fn nice_inflect<'a>( self, singular: &'a str, plural: &'a str, ) -> NiceInflected<'a, NiceU32>

§Inflect a String.
Source§

impl NiceInflection<NiceU32> for i32

Source§

fn nice_inflect<'a>( self, singular: &'a str, plural: &'a str, ) -> NiceInflected<'a, NiceU32>

§Inflect a String.
Source§

impl Ord for NiceU32

Source§

fn cmp(&self, rhs: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for NiceU32

Source§

fn eq(&self, rhs: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for NiceU32

Source§

fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for NiceU32

Source§

impl Eq for NiceU32

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.