macro_rules! itoa {
($into_dtoa:expr) => { ... };
}Expand description
Quickly format an integer to a &str
This creates an ItoaTmp from an Integer, returns the output &str, and immediately goes out of scope.
The function signature would look something like:
ⓘ
fn itoa<I: Integer>(integer: I) -> &'tmp str
where
'tmp: FreedAtEndOfStatementItoaTmp is created and immediately dropped, thus it cannot be stored:
ⓘ
let x = itoa!(10);
^^^^^^^^^- temporary value is freed at the end of this statement
assert_eq!(x, "10");
------------------- compile error: borrow later used hereYou must use the &str in 1 single statement:
assert_eq!(itoa!(10), "10"); // ok
if itoa!(10) == "10" {
// ok
}
// ok
let string: String = itoa!(10).to_string();
assert_eq!(string, "10");The macro expands to ItoaTmp::new().format(x):
// These are the same.
itoa!(10);
readable::toa::ItoaTmp::new().format(10);