The uint! macro for Uint literals
The above can also be written using the [uint!] macro. Within the macro arguments,
you can write Uint literals using the same syntax as Rust integer
literals, but using a capital U in the suffix instead of lowercase.
To use it simply import it in scope:
use uint;
Now constants can be created in decimal, hex, binary and even octal:
# use uint;
let avogadro = uint!;
let cow_key = uint!;
let bender = uint!;
The [uint!] macro recurses through the parse tree, so the above can equivalently be written
# use uint;
uint!
This latter form is particularly useful for lookup tables:
# use ;
const PRIMES: = uint!;
The macro will throw a compile time error if you try to create a constant that does not fit the type:
# use uint;
# uint!
error: Value too large for Uint<8>: 300
--> src/example.rs:1:14
|
1 | let sparta = 300_U8;
| ^^^^^^
References
- Rust integer literals syntax.