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]
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for NumWords
impl Send for NumWords
impl Sync for NumWords
impl Unpin for NumWords
impl UnwindSafe for NumWords
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,