Struct shortscale::extra::NumWords[][src]

pub struct NumWords { /* fields omitted */ }

Expose shortscale Display trait implementation
for easy to_string() or write!() into an existing String.

This experiment was supposed to be faster than shortscale because we can eliminate the allocation of a new String. However, the overhead of making multiple fmt::Formatter.write_str() calls turned out to be greater than the cost of String allocation.

The simpler solution was to add a string writer function to shortscale directly mutating an existing string, rother than going through the formatter code.

Example

use shortscale;
use std::fmt::Write;

let mut buf = String::with_capacity(100);
let numwords = shortscale::extra::NumWords::new(420_000_999_015);

// write to buffer
println!("buf.len() before: {}", buf.len());
write!(&mut buf, "{}", numwords).unwrap();
println!("buf.len()  after: {}", buf.len());

// or simply convert to String (may do multiple allocs)
assert_eq!(
    numwords.to_string(),
    "four hundred and twenty billion nine hundred \
    and ninety nine thousand and fifteen"
    );

Implementations

impl NumWords[src]

pub fn new(n: u64) -> Self[src]

Trait Implementations

impl Debug for NumWords[src]

impl Display for NumWords[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.