Type Definition dactyl::NiceU64

source ·
pub type NiceU64 = NiceWrapper<SIZE>;
Expand description

NiceU64 provides a quick way to convert a u64 into a formatted byte string for e.g. printing. Commas are added for every thousand.

That’s it!

Examples

use dactyl::NiceU64;
assert_eq!(
    NiceU64::from(33231_u64).as_str(),
    "33,231"
);

Traits

Rustdoc doesn’t do a good job at documenting type alias implementations, but NiceU64 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 NiceU64 with:

  • From<u64>
  • From<Option<u64>>
  • From<NonZeroU64>
  • From<Option<NonZeroU64>>
  • From<usize>
  • From<Option<usize>>
  • From<NonZeroUsize>
  • From<Option<NonZeroUsize>>

When converting from a None, the result will be equivalent to zero.

For targets with 128-bit pointers, usize values cannot exceed u64::MAX or a panic will ensue.

Implementations§

source§

impl NiceU64

source

pub fn with_separator(num: u64, 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 [NiceU64::from] instead.

Examples
use dactyl::NiceU64;

let num = NiceU64::from(3141592653589793238_u64);
assert_eq!(num.as_str(), "3,141,592,653,589,793,238");

let num = NiceU64::with_separator(3141592653589793238_u64, b'_');
assert_eq!(num.as_str(), "3_141_592_653_589_793_238");
Panics

This method will panic if the separator is invalid ASCII.

Trait Implementations§

source§

impl Default for NiceU64

source§

fn default() -> Self

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

impl From<NonZeroU64> for NiceU64

source§

fn from(num: NonZeroU64) -> Self

Converts to this type from the input type.
source§

impl From<NonZeroUsize> for NiceU64

source§

fn from(num: NonZeroUsize) -> Self

Converts to this type from the input type.
source§

impl From<u64> for NiceU64

source§

fn from(num: u64) -> Self

Converts to this type from the input type.
source§

impl From<usize> for NiceU64

source§

fn from(num: usize) -> Self

Converts to this type from the input type.