1 stable release
1.0.0 | May 10, 2020 |
---|
#276 in Value formatting
18KB
318 lines
to-str
Generic trait for efficient conversion to string.
Suitable for no_std
Performance
It is up to ToStr
implementation, but in general default impls are efficient alternative to Rust's core fmt
Integers
Performance in general is close to itoa
, but lags a bit behind due to some missing optimization opportunities (possibly due to slices in ToStr
).
Differently from itoa
though the implementation avoids generics per integer type, but rather uses common functions for u8
, u64
and u128
types
lib.rs
:
no_std
friendly interface for conversion to str
type Buffer = to_str::Buffer64;
let mut buf = String::new();
let _ = buf.push_str(Buffer::fmt(5usize).as_str());
assert_eq!(buf, "5");
buf.push_str(Buffer::fmt(0usize).as_str());
assert_eq!(buf, "50");
buf.push_str(Buffer::fmt(&5usize).as_str());
assert_eq!(buf, "505");
buf.push_str(Buffer::fmt(&mut 0usize).as_str());
assert_eq!(buf, "5050");