macro_rules! keccak { ($data:expr $(,)?) => { ... }; ($($part:expr),* $(,)?) => { ... }; }
Expand description
Macro to create Ethereum digest values for compile-time hashed input.
Examples
Basic usage:
assert_eq!(
Digest::of("Hello Ethereum!"),
keccak!(b"Hello Ethereum!",),
);
The input can be split into parts:
assert_eq!(
Digest::of("Hello Ethereum!"),
keccak!(b"Hello", b" ", b"Ethereum!"),
);
Note that this can be used in const
contexts, but unfortunately not in
pattern matching contexts:
const DIGEST: Digest = keccak!(b"I will never change...");
ⓘ
match Digest::of("thing") {
keccak!("thing") => println!("matches"),
_ => println!("doesn't match"),
}
Additionally, this can be composed with other macros and constant expressions:
const FILEHASH: Digest = keccak!(include_bytes!("../README.md"));
const PIHASH: Digest = keccak!(concat!("const PI = ", 3.14).as_bytes());