]> Untitled Git - bitcoindevkit.org/blob
80e0b28f4a51b688e97d8a1bc67d858298ee15ca
[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::secp256k1::hashes - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.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-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-46132b98.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.85.0-nightly (4ba4ac612 2024-12-18)" data-channel="nightly" data-search-js="search-036cda7a.js" data-settings-js="settings-0f613d39.js" ><script src="../../../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.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_<wbr>chain</a><span class="version">0.21.1</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In bdk_<wbr>chain::<wbr>bitcoin::<wbr>secp256k1::<wbr>hashes</a></h2></div></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"><span class="rustdoc-breadcrumbs"><a href="../../../index.html">bdk_chain</a>::<wbr><a href="../../index.html">bitcoin</a>::<wbr><a href="../index.html">secp256k1</a>::<wbr><a href="index.html">hashes</a></span><h1>Macro <span class="macro">sha256t_hash_newtype</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>macro_rules! sha256t_hash_newtype {
2 ($($(#[$($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)*])* _);)+) =&gt; { ... };
3 }</code></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::secp256k1::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>