]> Untitled Git - bitcoindevkit.org/blob
dd39c7d458c639226ca3631e1be50e46633d133e
[bitcoindevkit.org] /
1 <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Macro used to define a newtype tagged hash."><title>sha256t_hash_newtype in bdk_chain::bitcoin::hashes - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../../static.files/rustdoc-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="bdk_chain" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (78a775127 2024-05-11)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc macro"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../../bdk_chain/index.html"><img src="https://github.com/bitcoindevkit/bdk/raw/master/static/bdk.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../../bdk_chain/index.html"><img src="https://github.com/bitcoindevkit/bdk/raw/master/static/bdk.png" alt="logo"></a><h2><a href="../../../bdk_chain/index.html">bdk_chain</a><span class="version">0.18.0</span></h2></div><div class="sidebar-elems"><h2><a href="index.html">In bdk_chain::bitcoin::hashes</a></h2></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Macro <a href="../../index.html">bdk_chain</a>::<wbr><a href="../index.html">bitcoin</a>::<wbr><a href="index.html">hashes</a>::<wbr><a class="macro" href="#">sha256t_hash_newtype</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><pre class="rust item-decl"><span class="macro">macro_rules!</span> sha256t_hash_newtype {
2 ($($(<span class="attr">#[$(<span class="macro-nonterminal">$tag_attr</span>:tt)<span class="kw-2">*</span>]</span>)* <span class="macro-nonterminal">$tag_vis</span>:vis <span class="kw">struct </span><span class="macro-nonterminal">$tag</span>:ident = <span class="macro-nonterminal">$constructor</span>:tt($(<span class="macro-nonterminal">$tag_value</span>:tt)+); $(<span class="attr">#[$(<span class="macro-nonterminal">$hash_attr</span>:tt)<span class="kw-2">*</span>]</span>)* <span class="macro-nonterminal">$hash_vis</span>:vis <span class="kw">struct </span><span class="macro-nonterminal">$hash_name</span>:ident($(<span class="attr">#[$(<span class="macro-nonterminal">$field_attr</span>:tt)<span class="kw-2">*</span>]</span>)* <span class="kw">_</span>);)+) =&gt; { ... };
3 }</pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Macro used to define a newtype tagged hash.</p>
4 <p>This macro creates two types:</p>
5 <ul>
6 <li>a tag struct</li>
7 <li>a hash wrapper</li>
8 </ul>
9 <p>The syntax is:</p>
10
11 <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">sha256t_hash_newtype!</span> {
12 <span class="doccomment">/// Optional documentation details here.
13 /// Summary is always generated.
14 </span><span class="kw">pub struct </span>FooTag = hash_str(<span class="string">"foo"</span>);
15
16 <span class="doccomment">/// A foo hash.
17 </span><span class="comment">// Direction works just like in case of hash_newtype! macro.
18 </span><span class="attr">#[hash_newtype(forward)]
19 </span><span class="kw">pub struct </span>FooHash(<span class="kw">_</span>);
20 }</code></pre></div>
21 <p>The structs must be defined in this order - tag first, then hash type. <code>hash_str</code> marker
22 says the midstate should be generated by hashing the supplied string in a way described in
23 BIP-341. Alternatively, you can supply <code>hash_bytes</code> to hash raw bytes. If you have the midstate
24 already pre-computed and prefer <strong>compiler</strong> performance to readability you may use
25 <code>raw(MIDSTATE_BYTES, HASHED_BYTES_LENGTH)</code> instead.</p>
26 <p>Both visibility modifiers and attributes are optional and passed to inner structs (excluding
27 <code>#[hash_newtype(...)]</code>). The attributes suffer same compiler performance limitations as in
28 <a href="macro.hash_newtype.html" title="macro bdk_chain::bitcoin::hashes::hash_newtype"><code>hash_newtype</code></a> macro.</p>
29 <p>The macro accepts multiple inputs so you can define multiple hash newtypes in one macro call.
30 Just make sure to enter the structs in order <code>Tag0</code>, <code>Hash0</code>, <code>Tag1</code>, <code>Hash1</code>…</p>
31 </div></details></section></div></main></body></html>