struct.VariantInfo.html 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta name="generator" content="rustdoc">
  7. <meta name="description" content="API documentation for the Rust `VariantInfo` struct in crate `synstructure`.">
  8. <meta name="keywords" content="rust, rustlang, rust-lang, VariantInfo">
  9. <title>synstructure::VariantInfo - Rust</title>
  10. <link rel="stylesheet" type="text/css" href="../normalize.css">
  11. <link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle">
  12. <link rel="stylesheet" type="text/css" href="../dark.css">
  13. <link rel="stylesheet" type="text/css" href="../main.css" id="themeStyle">
  14. <script src="../storage.js"></script>
  15. </head>
  16. <body class="rustdoc struct">
  17. <!--[if lte IE 8]>
  18. <div class="warning">
  19. This old browser is unsupported and will most likely display funky
  20. things.
  21. </div>
  22. <![endif]-->
  23. <nav class="sidebar">
  24. <div class="sidebar-menu">&#9776;</div>
  25. <p class='location'>Struct VariantInfo</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#fields">Fields</a><div class="sidebar-links"><a href="#structfield.prefix">prefix</a></div><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.bindings">bindings</a><a href="#method.bindings_mut">bindings_mut</a><a href="#method.ast">ast</a><a href="#method.omitted_bindings">omitted_bindings</a><a href="#method.pat">pat</a><a href="#method.construct">construct</a><a href="#method.each">each</a><a href="#method.fold">fold</a><a href="#method.filter">filter</a><a href="#method.remove_binding">remove_binding</a><a href="#method.bind_with">bind_with</a><a href="#method.binding_name">binding_name</a><a href="#method.referenced_ty_params">referenced_ty_params</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Debug">Debug</a><a href="#impl-Clone">Clone</a><a href="#impl-PartialEq">PartialEq</a><a href="#impl-Eq">Eq</a><a href="#impl-Hash">Hash</a></div></div><p class='location'><a href='index.html'>synstructure</a></p><script>window.sidebarCurrent = {name: 'VariantInfo', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div>
  26. </nav>
  27. <div class="theme-picker">
  28. <button id="theme-picker" aria-label="Pick another theme!">
  29. <img src="../brush.svg" width="18" alt="Pick another theme!">
  30. </button>
  31. <div id="theme-choices"></div>
  32. </div>
  33. <script src="../theme.js"></script>
  34. <nav class="sub">
  35. <form class="search-form js-only">
  36. <div class="search-container">
  37. <input class="search-input" name="search"
  38. autocomplete="off"
  39. placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
  40. type="search">
  41. </div>
  42. </form>
  43. </nav>
  44. <section id='main' class="content">
  45. <h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>synstructure</a>::<wbr><a class="struct" href=''>VariantInfo</a></span><span class='out-of-band'><span id='render-detail'>
  46. <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
  47. [<span class='inner'>&#x2212;</span>]
  48. </a>
  49. </span><a class='srclink' href='../src/synstructure/lib.rs.html#324-330' title='goto source code'>[src]</a></span></h1>
  50. <pre class='rust struct'>pub struct VariantInfo&lt;'a&gt; {
  51. pub prefix: <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;'a <a class="struct" href="../syn/ident/struct.Ident.html" title="struct syn::ident::Ident">Ident</a>&gt;,
  52. // some fields omitted
  53. }</pre><div class='docblock'><p>A wrapper around a <code>syn</code> <code>DeriveInput</code>'s variant which provides utilities
  54. for destructuring <code>Variant</code>s with <code>match</code> expressions.</p>
  55. </div><h2 id='fields' class='fields small-section-header'>
  56. Fields<a href='#fields' class='anchor'></a></h2><span id="structfield.prefix" class="structfield small-section-header">
  57. <a href="#structfield.prefix" class="anchor field"></a>
  58. <span id="prefix.v" class='invisible'>
  59. <code>prefix: <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;'a <a class="struct" href="../syn/ident/struct.Ident.html" title="struct syn::ident::Ident">Ident</a>&gt;</code>
  60. </span></span>
  61. <h2 id='methods' class='small-section-header'>
  62. Methods<a href='#methods' class='anchor'></a>
  63. </h2>
  64. <h3 id='impl' class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="struct" href="../synstructure/struct.VariantInfo.html" title="struct synstructure::VariantInfo">VariantInfo</a>&lt;'a&gt;</code><a href='#impl' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#376-854' title='goto source code'>[src]</a></span></h3>
  65. <div class='impl-items'><h4 id='method.bindings' class="method"><span id='bindings.v' class='invisible'><code>pub fn <a href='#method.bindings' class='fnname'>bindings</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[</a><a class="struct" href="../synstructure/struct.BindingInfo.html" title="struct synstructure::BindingInfo">BindingInfo</a>&lt;'a&gt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#405-407' title='goto source code'>[src]</a></span></h4>
  66. <div class='docblock'><p>Returns a slice of the bindings in this Variant.</p>
  67. </div><h4 id='method.bindings_mut' class="method"><span id='bindings_mut.v' class='invisible'><code>pub fn <a href='#method.bindings_mut' class='fnname'>bindings_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;mut [</a><a class="struct" href="../synstructure/struct.BindingInfo.html" title="struct synstructure::BindingInfo">BindingInfo</a>&lt;'a&gt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#410-412' title='goto source code'>[src]</a></span></h4>
  68. <div class='docblock'><p>Returns a mut slice of the bindings in this Variant.</p>
  69. </div><h4 id='method.ast' class="method"><span id='ast.v' class='invisible'><code>pub fn <a href='#method.ast' class='fnname'>ast</a>(&amp;self) -&gt; <a class="struct" href="../synstructure/struct.VariantAst.html" title="struct synstructure::VariantAst">VariantAst</a>&lt;'a&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#416-418' title='goto source code'>[src]</a></span></h4>
  70. <div class='docblock'><p>Returns a <code>VariantAst</code> object which contains references to the
  71. underlying <code>syn</code> AST node which this <code>Variant</code> was created from.</p>
  72. </div><h4 id='method.omitted_bindings' class="method"><span id='omitted_bindings.v' class='invisible'><code>pub fn <a href='#method.omitted_bindings' class='fnname'>omitted_bindings</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#421-423' title='goto source code'>[src]</a></span></h4>
  73. <div class='docblock'><p>True if any bindings were omitted due to a <code>filter</code> call.</p>
  74. </div><h4 id='method.pat' class="method"><span id='pat.v' class='invisible'><code>pub fn <a href='#method.pat' class='fnname'>pat</a>(&amp;self) -&gt; <a class="struct" href="../quote/tokens/struct.Tokens.html" title="struct quote::tokens::Tokens">Tokens</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#450-487' title='goto source code'>[src]</a></span></h4>
  75. <div class='docblock'><p>Generates the match-arm pattern which could be used to match against this Variant.</p>
  76. <h1 id="example" class="section-header"><a href="#example">Example</a></h1>
  77. <pre class="rust rust-example-rendered">
  78. <span class="kw">let</span> <span class="ident">di</span> <span class="op">=</span> <span class="ident">syn</span>::<span class="ident">parse_derive_input</span>(<span class="string">r#&quot;
  79. enum A {
  80. B(i32, i32),
  81. C(u32),
  82. }
  83. &quot;#</span>).<span class="ident">unwrap</span>();
  84. <span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">Structure</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span><span class="ident">di</span>);
  85. <span class="macro">assert_eq</span><span class="macro">!</span>(
  86. <span class="ident">s</span>.<span class="ident">variants</span>()[<span class="number">0</span>].<span class="ident">pat</span>(),
  87. <span class="macro">quote</span><span class="macro">!</span>{
  88. <span class="ident">A</span>::<span class="ident">B</span>(<span class="kw-2">ref</span> <span class="ident">__binding_0</span>, <span class="kw-2">ref</span> <span class="ident">__binding_1</span>,)
  89. }
  90. );</pre>
  91. </div><h4 id='method.construct' class="method"><span id='construct.v' class='invisible'><code>pub fn <a href='#method.construct' class='fnname'>construct</a>&lt;F, T&gt;(&amp;self, func: F) -&gt; <a class="struct" href="../quote/tokens/struct.Tokens.html" title="struct quote::tokens::Tokens">Tokens</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;<a class="struct" href="../syn/data/struct.Field.html" title="struct syn::data::Field">Field</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -&gt; T,<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../quote/to_tokens/trait.ToTokens.html" title="trait quote::to_tokens::ToTokens">ToTokens</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#525-559' title='goto source code'>[src]</a></span></h4>
  92. <div class='docblock'><p>Generates the token stream required to construct the current variant.</p>
  93. <p>The init array initializes each of the fields in the order they are written in <code>variant.ast().fields</code>.</p>
  94. <h1 id="example-1" class="section-header"><a href="#example-1">Example</a></h1>
  95. <pre class="rust rust-example-rendered">
  96. <span class="kw">let</span> <span class="ident">di</span> <span class="op">=</span> <span class="ident">syn</span>::<span class="ident">parse_derive_input</span>(<span class="string">r#&quot;
  97. enum A {
  98. B(usize, usize),
  99. C{ v: usize },
  100. }
  101. &quot;#</span>).<span class="ident">unwrap</span>();
  102. <span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">Structure</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span><span class="ident">di</span>);
  103. <span class="macro">assert_eq</span><span class="macro">!</span>(
  104. <span class="ident">s</span>.<span class="ident">variants</span>()[<span class="number">0</span>].<span class="ident">construct</span>(<span class="op">|</span>_, <span class="ident">i</span><span class="op">|</span> <span class="macro">quote</span><span class="macro">!</span>(#<span class="ident">i</span>)),
  105. <span class="macro">quote</span><span class="macro">!</span>{
  106. <span class="ident">A</span>::<span class="ident">B</span>(<span class="number">0usize</span>, <span class="number">1usize</span>,)
  107. }
  108. );
  109. <span class="macro">assert_eq</span><span class="macro">!</span>(
  110. <span class="ident">s</span>.<span class="ident">variants</span>()[<span class="number">1</span>].<span class="ident">construct</span>(<span class="op">|</span>_, <span class="ident">i</span><span class="op">|</span> <span class="macro">quote</span><span class="macro">!</span>(#<span class="ident">i</span>)),
  111. <span class="macro">quote</span><span class="macro">!</span>{
  112. <span class="ident">A</span>::<span class="ident">C</span>{ <span class="ident">v</span>: <span class="number">0usize</span>, }
  113. }
  114. );</pre>
  115. </div><h4 id='method.each' class="method"><span id='each.v' class='invisible'><code>pub fn <a href='#method.each' class='fnname'>each</a>&lt;F, R&gt;(&amp;self, f: F) -&gt; <a class="struct" href="../quote/tokens/struct.Tokens.html" title="struct quote::tokens::Tokens">Tokens</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;<a class="struct" href="../synstructure/struct.BindingInfo.html" title="struct synstructure::BindingInfo">BindingInfo</a>) -&gt; R,<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../quote/to_tokens/trait.ToTokens.html" title="trait quote::to_tokens::ToTokens">ToTokens</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#594-607' title='goto source code'>[src]</a></span></h4>
  116. <div class='docblock'><p>Runs the passed-in function once for each bound field, passing in a <code>BindingInfo</code>.
  117. and generating a <code>match</code> arm which evaluates the returned tokens.</p>
  118. <p>This method will ignore fields which are ignored through the <code>filter</code>
  119. method.</p>
  120. <h1 id="example-2" class="section-header"><a href="#example-2">Example</a></h1>
  121. <pre class="rust rust-example-rendered">
  122. <span class="kw">let</span> <span class="ident">di</span> <span class="op">=</span> <span class="ident">syn</span>::<span class="ident">parse_derive_input</span>(<span class="string">r#&quot;
  123. enum A {
  124. B(i32, i32),
  125. C(u32),
  126. }
  127. &quot;#</span>).<span class="ident">unwrap</span>();
  128. <span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">Structure</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span><span class="ident">di</span>);
  129. <span class="macro">assert_eq</span><span class="macro">!</span>(
  130. <span class="ident">s</span>.<span class="ident">variants</span>()[<span class="number">0</span>].<span class="ident">each</span>(<span class="op">|</span><span class="ident">bi</span><span class="op">|</span> <span class="macro">quote</span><span class="macro">!</span>(<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, #<span class="ident">bi</span>))),
  131. <span class="macro">quote</span><span class="macro">!</span>{
  132. <span class="ident">A</span>::<span class="ident">B</span>(<span class="kw-2">ref</span> <span class="ident">__binding_0</span>, <span class="kw-2">ref</span> <span class="ident">__binding_1</span>,) <span class="op">=&gt;</span> {
  133. { <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">__binding_0</span>) }
  134. { <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">__binding_1</span>) }
  135. }
  136. }
  137. );</pre>
  138. </div><h4 id='method.fold' class="method"><span id='fold.v' class='invisible'><code>pub fn <a href='#method.fold' class='fnname'>fold</a>&lt;F, I, R&gt;(&amp;self, init: I, f: F) -&gt; <a class="struct" href="../quote/tokens/struct.Tokens.html" title="struct quote::tokens::Tokens">Tokens</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="struct" href="../quote/tokens/struct.Tokens.html" title="struct quote::tokens::Tokens">Tokens</a>, &amp;<a class="struct" href="../synstructure/struct.BindingInfo.html" title="struct synstructure::BindingInfo">BindingInfo</a>) -&gt; R,<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../quote/to_tokens/trait.ToTokens.html" title="trait quote::to_tokens::ToTokens">ToTokens</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../quote/to_tokens/trait.ToTokens.html" title="trait quote::to_tokens::ToTokens">ToTokens</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#642-654' title='goto source code'>[src]</a></span></h4>
  139. <div class='docblock'><p>Runs the passed-in function once for each bound field, passing in the
  140. result of the previous call, and a <code>BindingInfo</code>. generating a <code>match</code>
  141. arm which evaluates to the resulting tokens.</p>
  142. <p>This method will ignore fields which are ignored through the <code>filter</code>
  143. method.</p>
  144. <h1 id="example-3" class="section-header"><a href="#example-3">Example</a></h1>
  145. <pre class="rust rust-example-rendered">
  146. <span class="kw">let</span> <span class="ident">di</span> <span class="op">=</span> <span class="ident">syn</span>::<span class="ident">parse_derive_input</span>(<span class="string">r#&quot;
  147. enum A {
  148. B(i32, i32),
  149. C(u32),
  150. }
  151. &quot;#</span>).<span class="ident">unwrap</span>();
  152. <span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">Structure</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span><span class="ident">di</span>);
  153. <span class="macro">assert_eq</span><span class="macro">!</span>(
  154. <span class="ident">s</span>.<span class="ident">variants</span>()[<span class="number">0</span>].<span class="ident">fold</span>(<span class="macro">quote</span><span class="macro">!</span>(<span class="number">0</span>), <span class="op">|</span><span class="ident">acc</span>, <span class="ident">bi</span><span class="op">|</span> <span class="macro">quote</span><span class="macro">!</span>(#<span class="ident">acc</span> <span class="op">+</span> #<span class="ident">bi</span>)),
  155. <span class="macro">quote</span><span class="macro">!</span>{
  156. <span class="ident">A</span>::<span class="ident">B</span>(<span class="kw-2">ref</span> <span class="ident">__binding_0</span>, <span class="kw-2">ref</span> <span class="ident">__binding_1</span>,) <span class="op">=&gt;</span> {
  157. <span class="number">0</span> <span class="op">+</span> <span class="ident">__binding_0</span> <span class="op">+</span> <span class="ident">__binding_1</span>
  158. }
  159. }
  160. );</pre>
  161. </div><h4 id='method.filter' class="method"><span id='filter.v' class='invisible'><code>pub fn <a href='#method.filter' class='fnname'>filter</a>&lt;F&gt;(&amp;mut self, f: F) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;<a class="struct" href="../synstructure/struct.BindingInfo.html" title="struct synstructure::BindingInfo">BindingInfo</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#698-708' title='goto source code'>[src]</a></span></h4>
  162. <div class='docblock'><p>Filter the bindings created by this <code>Variant</code> object. This has 2 effects:</p>
  163. <ul>
  164. <li>
  165. <p>The bindings will no longer appear in match arms generated by methods
  166. on this <code>Variant</code> or its subobjects.</p>
  167. </li>
  168. <li>
  169. <p>Impl blocks created with the <code>bound_impl</code> or <code>unsafe_bound_impl</code>
  170. method only consider type parameters referenced in the types of
  171. non-filtered fields.</p>
  172. </li>
  173. </ul>
  174. <h1 id="example-4" class="section-header"><a href="#example-4">Example</a></h1>
  175. <pre class="rust rust-example-rendered">
  176. <span class="kw">let</span> <span class="ident">di</span> <span class="op">=</span> <span class="ident">syn</span>::<span class="ident">parse_derive_input</span>(<span class="string">r#&quot;
  177. enum A {
  178. B{ a: i32, b: i32 },
  179. C{ a: u32 },
  180. }
  181. &quot;#</span>).<span class="ident">unwrap</span>();
  182. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">Structure</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span><span class="ident">di</span>);
  183. <span class="ident">s</span>.<span class="ident">variants_mut</span>()[<span class="number">0</span>].<span class="ident">filter</span>(<span class="op">|</span><span class="ident">bi</span><span class="op">|</span> {
  184. <span class="ident">bi</span>.<span class="ident">ast</span>().<span class="ident">ident</span> <span class="op">==</span> <span class="prelude-val">Some</span>(<span class="string">&quot;b&quot;</span>.<span class="ident">into</span>())
  185. });
  186. <span class="macro">assert_eq</span><span class="macro">!</span>(
  187. <span class="ident">s</span>.<span class="ident">each</span>(<span class="op">|</span><span class="ident">bi</span><span class="op">|</span> <span class="macro">quote</span><span class="macro">!</span>(<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, #<span class="ident">bi</span>))),
  188. <span class="macro">quote</span><span class="macro">!</span>{
  189. <span class="ident">A</span>::<span class="ident">B</span>{ <span class="ident">b</span>: <span class="kw-2">ref</span> <span class="ident">__binding_1</span>, .. } <span class="op">=&gt;</span> {
  190. { <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">__binding_1</span>) }
  191. }
  192. <span class="ident">A</span>::<span class="ident">C</span>{ <span class="ident">a</span>: <span class="kw-2">ref</span> <span class="ident">__binding_0</span>, } <span class="op">=&gt;</span> {
  193. { <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">__binding_0</span>) }
  194. }
  195. }
  196. );</pre>
  197. </div><h4 id='method.remove_binding' class="method"><span id='remove_binding.v' class='invisible'><code>pub fn <a href='#method.remove_binding' class='fnname'>remove_binding</a>(&amp;mut self, idx: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#715-719' title='goto source code'>[src]</a></span></h4>
  198. <div class='docblock'><p>Remove the binding at the given index.</p>
  199. <h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
  200. <p>Panics if the index is out of range.</p>
  201. </div><h4 id='method.bind_with' class="method"><span id='bind_with.v' class='invisible'><code>pub fn <a href='#method.bind_with' class='fnname'>bind_with</a>&lt;F&gt;(&amp;mut self, f: F) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;<a class="struct" href="../synstructure/struct.BindingInfo.html" title="struct synstructure::BindingInfo">BindingInfo</a>) -&gt; <a class="enum" href="../synstructure/enum.BindStyle.html" title="enum synstructure::BindStyle">BindStyle</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#756-764' title='goto source code'>[src]</a></span></h4>
  202. <div class='docblock'><p>Updates the <code>BindStyle</code> for each of the passed-in fields by calling the
  203. passed-in function for each <code>BindingInfo</code>.</p>
  204. <h1 id="example-5" class="section-header"><a href="#example-5">Example</a></h1>
  205. <pre class="rust rust-example-rendered">
  206. <span class="kw">let</span> <span class="ident">di</span> <span class="op">=</span> <span class="ident">syn</span>::<span class="ident">parse_derive_input</span>(<span class="string">r#&quot;
  207. enum A {
  208. B(i32, i32),
  209. C(u32),
  210. }
  211. &quot;#</span>).<span class="ident">unwrap</span>();
  212. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">Structure</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span><span class="ident">di</span>);
  213. <span class="ident">s</span>.<span class="ident">variants_mut</span>()[<span class="number">0</span>].<span class="ident">bind_with</span>(<span class="op">|</span><span class="ident">bi</span><span class="op">|</span> <span class="ident">BindStyle</span>::<span class="ident">RefMut</span>);
  214. <span class="macro">assert_eq</span><span class="macro">!</span>(
  215. <span class="ident">s</span>.<span class="ident">each</span>(<span class="op">|</span><span class="ident">bi</span><span class="op">|</span> <span class="macro">quote</span><span class="macro">!</span>(<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, #<span class="ident">bi</span>))),
  216. <span class="macro">quote</span><span class="macro">!</span>{
  217. <span class="ident">A</span>::<span class="ident">B</span>(<span class="kw-2">ref</span> <span class="kw-2">mut</span> <span class="ident">__binding_0</span>, <span class="kw-2">ref</span> <span class="kw-2">mut</span> <span class="ident">__binding_1</span>,) <span class="op">=&gt;</span> {
  218. { <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">__binding_0</span>) }
  219. { <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">__binding_1</span>) }
  220. }
  221. <span class="ident">A</span>::<span class="ident">C</span>(<span class="kw-2">ref</span> <span class="ident">__binding_0</span>,) <span class="op">=&gt;</span> {
  222. { <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">__binding_0</span>) }
  223. }
  224. }
  225. );</pre>
  226. </div><h4 id='method.binding_name' class="method"><span id='binding_name.v' class='invisible'><code>pub fn <a href='#method.binding_name' class='fnname'>binding_name</a>&lt;F&gt;(&amp;mut self, f: F) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;<a class="struct" href="../syn/data/struct.Field.html" title="struct syn::data::Field">Field</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -&gt; <a class="struct" href="../syn/ident/struct.Ident.html" title="struct syn::ident::Ident">Ident</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#807-815' title='goto source code'>[src]</a></span></h4>
  227. <div class='docblock'><p>Updates the binding name for each fo the passed-in fields by calling the
  228. passed-in function for each <code>BindingInfo</code>.</p>
  229. <p>The function will be called with the <code>BindingInfo</code> and its index in the
  230. enclosing variant.</p>
  231. <p>The default name is <code>__binding_{}</code> where <code>{}</code> is replaced with an
  232. increasing number.</p>
  233. <h1 id="example-6" class="section-header"><a href="#example-6">Example</a></h1>
  234. <pre class="rust rust-example-rendered">
  235. <span class="kw">let</span> <span class="ident">di</span> <span class="op">=</span> <span class="ident">syn</span>::<span class="ident">parse_derive_input</span>(<span class="string">r#&quot;
  236. enum A {
  237. B{ a: i32, b: i32 },
  238. C{ a: u32 },
  239. }
  240. &quot;#</span>).<span class="ident">unwrap</span>();
  241. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">Structure</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span><span class="ident">di</span>);
  242. <span class="ident">s</span>.<span class="ident">variants_mut</span>()[<span class="number">0</span>].<span class="ident">binding_name</span>(<span class="op">|</span><span class="ident">bi</span>, <span class="ident">i</span><span class="op">|</span> <span class="ident">bi</span>.<span class="ident">ident</span>.<span class="ident">clone</span>().<span class="ident">unwrap</span>());
  243. <span class="macro">assert_eq</span><span class="macro">!</span>(
  244. <span class="ident">s</span>.<span class="ident">each</span>(<span class="op">|</span><span class="ident">bi</span><span class="op">|</span> <span class="macro">quote</span><span class="macro">!</span>(<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, #<span class="ident">bi</span>))),
  245. <span class="macro">quote</span><span class="macro">!</span>{
  246. <span class="ident">A</span>::<span class="ident">B</span>{ <span class="ident">a</span>: <span class="kw-2">ref</span> <span class="ident">a</span>, <span class="ident">b</span>: <span class="kw-2">ref</span> <span class="ident">b</span>, } <span class="op">=&gt;</span> {
  247. { <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">a</span>) }
  248. { <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">b</span>) }
  249. }
  250. <span class="ident">A</span>::<span class="ident">C</span>{ <span class="ident">a</span>: <span class="kw-2">ref</span> <span class="ident">__binding_0</span>, } <span class="op">=&gt;</span> {
  251. { <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">__binding_0</span>) }
  252. }
  253. }
  254. );</pre>
  255. </div><h4 id='method.referenced_ty_params' class="method"><span id='referenced_ty_params.v' class='invisible'><code>pub fn <a href='#method.referenced_ty_params' class='fnname'>referenced_ty_params</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;&amp;'a <a class="struct" href="../syn/ident/struct.Ident.html" title="struct syn::ident::Ident">Ident</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#847-853' title='goto source code'>[src]</a></span></h4>
  256. <div class='docblock'><p>Returns a list of the type parameters which are referenced in this
  257. field's type.</p>
  258. <h1 id="caveat" class="section-header"><a href="#caveat">Caveat</a></h1>
  259. <p>If the field contains any macros in type position, all parameters will
  260. be considered bound. This is because we cannot determine which type
  261. parameters are bound by type macros.</p>
  262. <h1 id="example-7" class="section-header"><a href="#example-7">Example</a></h1>
  263. <pre class="rust rust-example-rendered">
  264. <span class="kw">let</span> <span class="ident">di</span> <span class="op">=</span> <span class="ident">syn</span>::<span class="ident">parse_derive_input</span>(<span class="string">r#&quot;
  265. struct A&lt;T, U&gt; {
  266. a: Option&lt;T&gt;,
  267. b: U,
  268. }
  269. &quot;#</span>).<span class="ident">unwrap</span>();
  270. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">Structure</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span><span class="ident">di</span>);
  271. <span class="macro">assert_eq</span><span class="macro">!</span>(
  272. <span class="ident">s</span>.<span class="ident">variants</span>()[<span class="number">0</span>].<span class="ident">bindings</span>()[<span class="number">0</span>].<span class="ident">referenced_ty_params</span>(),
  273. <span class="kw-2">&amp;</span>[<span class="kw-2">&amp;</span>(<span class="ident">syn</span>::<span class="ident">Ident</span>::<span class="ident">from</span>(<span class="string">&quot;T&quot;</span>))]
  274. );</pre>
  275. </div></div>
  276. <h2 id='implementations' class='small-section-header'>
  277. Trait Implementations<a href='#implementations' class='anchor'></a>
  278. </h2>
  279. <h3 id='impl-Debug' class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../synstructure/struct.VariantInfo.html" title="struct synstructure::VariantInfo">VariantInfo</a>&lt;'a&gt;</code><a href='#impl-Debug' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#323' title='goto source code'>[src]</a></span></h3>
  280. <div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, __arg_0: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#323' title='goto source code'>[src]</a></span></h4>
  281. <div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
  282. </div></div><h3 id='impl-Clone' class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../synstructure/struct.VariantInfo.html" title="struct synstructure::VariantInfo">VariantInfo</a>&lt;'a&gt;</code><a href='#impl-Clone' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#323' title='goto source code'>[src]</a></span></h3>
  283. <div class='impl-items'><h4 id='method.clone' class="method"><span id='clone.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&amp;self) -&gt; <a class="struct" href="../synstructure/struct.VariantInfo.html" title="struct synstructure::VariantInfo">VariantInfo</a>&lt;'a&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#323' title='goto source code'>[src]</a></span></h4>
  284. <div class='docblock'><p>Returns a copy of the value. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone">Read more</a></p>
  285. </div><h4 id='method.clone_from' class="method"><span id='clone_from.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&amp;mut self, source: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>Self)</code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/clone.rs.html#112-114' title='goto source code'>[src]</a></span></h4>
  286. <div class='docblock'><p>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from">Read more</a></p>
  287. </div></div><h3 id='impl-PartialEq' class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a> for <a class="struct" href="../synstructure/struct.VariantInfo.html" title="struct synstructure::VariantInfo">VariantInfo</a>&lt;'a&gt;</code><a href='#impl-PartialEq' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#323' title='goto source code'>[src]</a></span></h3>
  288. <div class='impl-items'><h4 id='method.eq' class="method"><span id='eq.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../synstructure/struct.VariantInfo.html" title="struct synstructure::VariantInfo">VariantInfo</a>&lt;'a&gt;) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#323' title='goto source code'>[src]</a></span></h4>
  289. <div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
  290. </div><h4 id='method.ne' class="method"><span id='ne.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../synstructure/struct.VariantInfo.html" title="struct synstructure::VariantInfo">VariantInfo</a>&lt;'a&gt;) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#323' title='goto source code'>[src]</a></span></h4>
  291. <div class='docblock'><p>This method tests for <code>!=</code>.</p>
  292. </div></div><h3 id='impl-Eq' class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> for <a class="struct" href="../synstructure/struct.VariantInfo.html" title="struct synstructure::VariantInfo">VariantInfo</a>&lt;'a&gt;</code><a href='#impl-Eq' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#323' title='goto source code'>[src]</a></span></h3>
  293. <div class='impl-items'></div><h3 id='impl-Hash' class='impl'><span class='in-band'><code>impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> for <a class="struct" href="../synstructure/struct.VariantInfo.html" title="struct synstructure::VariantInfo">VariantInfo</a>&lt;'a&gt;</code><a href='#impl-Hash' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#323' title='goto source code'>[src]</a></span></h3>
  294. <div class='impl-items'><h4 id='method.hash' class="method"><span id='hash.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html#tymethod.hash' class='fnname'>hash</a>&lt;__H:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>&gt;(&amp;self, __arg_0: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>__H)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/synstructure/lib.rs.html#323' title='goto source code'>[src]</a></span></h4>
  295. <div class='docblock'><p>Feeds this value into the given [<code>Hasher</code>]. <a href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html#tymethod.hash">Read more</a></p>
  296. </div><h4 id='method.hash_slice' class="method"><span id='hash_slice.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html#method.hash_slice' class='fnname'>hash_slice</a>&lt;H&gt;(data: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[Self]</a>, state: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>H) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;H: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/hash/mod.rs.html#202-208' title='goto source code'>[src]</a></span></h4>
  297. <div class='docblock'><p>Feeds a slice of this type into the given [<code>Hasher</code>]. <a href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html#method.hash_slice">Read more</a></p>
  298. </div></div></section>
  299. <section id='search' class="content hidden"></section>
  300. <section class="footer"></section>
  301. <aside id="help" class="hidden">
  302. <div>
  303. <h1 class="hidden">Help</h1>
  304. <div class="shortcuts">
  305. <h2>Keyboard Shortcuts</h2>
  306. <dl>
  307. <dt><kbd>?</kbd></dt>
  308. <dd>Show this help dialog</dd>
  309. <dt><kbd>S</kbd></dt>
  310. <dd>Focus the search field</dd>
  311. <dt><kbd>↑</kbd></dt>
  312. <dd>Move up in search results</dd>
  313. <dt><kbd>↓</kbd></dt>
  314. <dd>Move down in search results</dd>
  315. <dt><kbd>↹</kbd></dt>
  316. <dd>Switch tab</dd>
  317. <dt><kbd>&#9166;</kbd></dt>
  318. <dd>Go to active search result</dd>
  319. <dt><kbd>+</kbd></dt>
  320. <dd>Expand all sections</dd>
  321. <dt><kbd>-</kbd></dt>
  322. <dd>Collapse all sections</dd>
  323. </dl>
  324. </div>
  325. <div class="infos">
  326. <h2>Search Tricks</h2>
  327. <p>
  328. Prefix searches with a type followed by a colon (e.g.
  329. <code>fn:</code>) to restrict the search to a given type.
  330. </p>
  331. <p>
  332. Accepted types are: <code>fn</code>, <code>mod</code>,
  333. <code>struct</code>, <code>enum</code>,
  334. <code>trait</code>, <code>type</code>, <code>macro</code>,
  335. and <code>const</code>.
  336. </p>
  337. <p>
  338. Search functions by type signature (e.g.
  339. <code>vec -> usize</code> or <code>* -> vec</code>)
  340. </p>
  341. </div>
  342. </div>
  343. </aside>
  344. <script>
  345. window.rootPath = "../";
  346. window.currentCrate = "synstructure";
  347. </script>
  348. <script src="../main.js"></script>
  349. <script defer src="../search-index.js"></script>
  350. </body>
  351. </html>