Macro rust_assembler::usize_to_str
source · macro_rules! usize_to_str { ( $n:expr; 1 ) => { ... }; ( $n:expr; 2 ) => { ... }; ( $n:expr; $len:expr ) => { ... }; ( $n:expr; $len:expr, u128 ) => { ... }; ( $n:expr; $len:expr, u128, 4 ) => { ... }; }
Expand description
Formats a positive number into a StackStr<N>. The parameters required are the number that must be converted and the length of N, namely the number of digits of the given number, separated by a semicolon. In case the number has less digits than the specified length, it will have trailing zeros, represented as their utf-8 value: 48. In case the length is less than required, it will result in undefined behavior.
Examples
assert_eq!("291", usize_to_str!(291; 3).str());
assert_eq!("0291", usize_to_str!(291; 4).str());
This function by default accepts values up to u64. If values up to u128 are needed, as a third parameter specify u128.
assert_eq!("00000123714384710312239874874388", usize_to_str!(123714384710312239874874388; 32, u128).str());
With u128 numbers it is rather slow. To get a faster version specify a length that is multiple of 4 and as a fourth paramter specify 4.
assert_eq!("00000123714384710312239874874388", usize_to_str!(123714384710312239874874388; 32, u128, 4).str());