macro_rules! sha256t_hash_newtype {
($($(#[$($tag_attr:tt)*])* $tag_vis:vis struct $tag:ident = $constructor:tt($($tag_value:tt)+); $(#[$($hash_attr:tt)*])* $hash_vis:vis struct $hash_name:ident($(#[$($field_attr:tt)*])* _);)+) => { ... };
}Expand description
Macro used to define a newtype tagged hash.
This macro creates two types:
- a tag struct
- a hash wrapper
The syntax is:
sha256t_hash_newtype! {
/// Optional documentation details here.
/// Summary is always generated.
pub struct FooTag = hash_str("foo");
/// A foo hash.
// Direction works just like in case of hash_newtype! macro.
#[hash_newtype(forward)]
pub struct FooHash(_);
}The structs must be defined in this order - tag first, then hash type. hash_str marker
says the midstate should be generated by hashing the supplied string in a way described in
BIP-341. Alternatively, you can supply hash_bytes to hash raw bytes. If you have the midstate
already pre-computed and prefer compiler performance to readability you may use
raw(MIDSTATE_BYTES, HASHED_BYTES_LENGTH) instead.
Both visibility modifiers and attributes are optional and passed to inner structs (excluding
#[hash_newtype(...)]). The attributes suffer same compiler performance limitations as in
hash_newtype macro.
The macro accepts multiple inputs so you can define multiple hash newtypes in one macro call.
Just make sure to enter the structs in order Tag0, Hash0, Tag1, Hash1…