Macro ethdigest::digest

source ·
macro_rules! digest {
    ($digest:expr $(,)?) => { ... };
}
Expand description

Macro to create Ethereum digest values from string literals that get parsed at compile time. A compiler error will be generated if an invalid digest is specified.

Examples

Basic usage:

for digest in [
    digest!("0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"),
    digest!("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"),
] {
    assert_eq!(digest, Digest([0xee; 32]));
}

The macro generate compile errors on invalid input:

let _ = digest!("not a valid hex digest literal!");

Note that this can be used in const contexts, but unfortunately not in pattern matching contexts:

const DIGEST: Digest = digest!("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20");
match Digest::of("thing") {
    digest!("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20") => println!("matches"),
    _ => println!("doesn't match"),
}