macro_rules! usize_to_str {
    ( $bytes:expr, 0 ) => { ... };
    ( $n:expr, 1, as_str ) => { ... };
    ( $n:expr, 1, as_byte ) => { ... };
    ( $n:expr, 2, as_bytes ) => { ... };
    ( $n:expr, 2, as_str ) => { ... };
    ( $n:expr, 3, as_bytes ) => { ... };
    ( $n:expr, 3, as_str ) => { ... };
    ( $n:expr, 4, as_bytes ) => { ... };
    ( $n:expr, 4, as_str ) => { ... };
    ( $n:expr, 5, as_bytes ) => { ... };
    ( $n:expr, 5, as_str ) => { ... };
}
Expand description

Converts a positive integer to its str value, expressed either as &str or [u8, n], where n is the number of desired digits (max 5). No heap allocations are implied.

Examples

 
assert_eq!("291", usize_to_str!(291, 3, as_str));
assert_eq!([50, 57, 49], usize_to_str!(291, 3, as_bytes));
 

If asked as_str, it doesn’t matter if the number of specified digits is greater than the number of actual digits of the number passed as parameter. If asked as_bytes, it will return traling 0s, expressed as their byte value (48).

 
assert_eq!("4", usize_to_str!(4, 5, as_str));
assert_eq!([48, 48, 48, 48, 52], usize_to_str!(4, 5, as_bytes));