index.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 `quote` crate.">
  8. <meta name="keywords" content="rust, rustlang, rust-lang, quote">
  9. <title>quote - 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 mod">
  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'>Crate quote</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#macros">Macros</a></li><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'quote', ty: 'mod', relpath: '../'};</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'>Crate <a class="mod" href=''>quote</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/quote/lib.rs.html#1-252' title='goto source code'>[src]</a></span></h1>
  50. <div class='docblock'><p>Quasi-quoting without a Syntex dependency, intended for use with <a href="https://github.com/rust-lang/rfcs/blob/master/text/1681-macros-1.1.md">Macros
  51. 1.1</a>.</p>
  52. <pre><code class="language-toml">[dependencies]
  53. quote = &quot;0.3&quot;
  54. </code></pre>
  55. <div class='information'><div class='tooltip ignore'>ⓘ<span class='tooltiptext'>This example is not tested</span></div></div><pre class="rust rust-example-rendered ignore">
  56. <span class="attribute">#[<span class="ident">macro_use</span>]</span>
  57. <span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">quote</span>;</pre>
  58. <p>Interpolation is done with <code>#var</code>:</p>
  59. <pre><code class="language-text">let tokens = quote! {
  60. struct SerializeWith #generics #where_clause {
  61. value: &amp;'a #field_ty,
  62. phantom: ::std::marker::PhantomData&lt;#item_ty&gt;,
  63. }
  64. impl #generics serde::Serialize for SerializeWith #generics #where_clause {
  65. fn serialize&lt;S&gt;(&amp;self, s: &amp;mut S) -&gt; Result&lt;(), S::Error&gt;
  66. where S: serde::Serializer
  67. {
  68. #path(self.value, s)
  69. }
  70. }
  71. SerializeWith {
  72. value: #value,
  73. phantom: ::std::marker::PhantomData::&lt;#item_ty&gt;,
  74. }
  75. };
  76. </code></pre>
  77. <p>Repetition is done using <code>#(...)*</code> or <code>#(...),*</code> very similar to <code>macro_rules!</code>:</p>
  78. <ul>
  79. <li><code>#(#var)*</code> - no separators</li>
  80. <li><code>#(#var),*</code> - the character before the asterisk is used as a separator</li>
  81. <li><code>#( struct #var; )*</code> - the repetition can contain other things</li>
  82. <li><code>#( #k =&gt; println!(&quot;{}&quot;, #v), )*</code> - even multiple interpolations</li>
  83. </ul>
  84. <p>The return type of <code>quote!</code> is <code>quote::Tokens</code>. Tokens can be interpolated into
  85. other quotes:</p>
  86. <pre><code class="language-text">let t = quote! { /* ... */ };
  87. return quote! { /* ... */ #t /* ... */ };
  88. </code></pre>
  89. <p>Call <code>to_string()</code> or <code>as_str()</code> on a Tokens to get a <code>String</code> or <code>&amp;str</code> of Rust
  90. code.</p>
  91. <p>The <code>quote!</code> macro relies on deep recursion so some large invocations may fail
  92. with &quot;recursion limit reached&quot; when you compile. If it fails, bump up the
  93. recursion limit by adding <code>#![recursion_limit = &quot;128&quot;]</code> to your crate. An even
  94. higher limit may be necessary for especially large invocations.</p>
  95. </div><h2 id='macros' class='section-header'><a href="#macros">Macros</a></h2>
  96. <table>
  97. <tr class=' module-item'>
  98. <td><a class="macro" href="macro.quote.html"
  99. title='macro quote::quote'>quote</a></td>
  100. <td class='docblock-short'>
  101. <p>The whole point.</p>
  102. </td>
  103. </tr></table><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
  104. <table>
  105. <tr class=' module-item'>
  106. <td><a class="struct" href="struct.ByteStr.html"
  107. title='struct quote::ByteStr'>ByteStr</a></td>
  108. <td class='docblock-short'>
  109. <p>Wrap a <code>&amp;str</code> so it interpolates as a byte-string: <code>b&quot;abc&quot;</code>.</p>
  110. </td>
  111. </tr>
  112. <tr class=' module-item'>
  113. <td><a class="struct" href="struct.Hex.html"
  114. title='struct quote::Hex'>Hex</a></td>
  115. <td class='docblock-short'>
  116. <p>Wrap an integer so it interpolates as a hexadecimal.</p>
  117. </td>
  118. </tr>
  119. <tr class=' module-item'>
  120. <td><a class="struct" href="struct.Ident.html"
  121. title='struct quote::Ident'>Ident</a></td>
  122. <td class='docblock-short'>
  123. <p>An identifier that should be interpolated without quotes.</p>
  124. </td>
  125. </tr>
  126. <tr class=' module-item'>
  127. <td><a class="struct" href="struct.Tokens.html"
  128. title='struct quote::Tokens'>Tokens</a></td>
  129. <td class='docblock-short'>
  130. <p>Tokens produced by a <code>quote!(...)</code> invocation.</p>
  131. </td>
  132. </tr></table><h2 id='traits' class='section-header'><a href="#traits">Traits</a></h2>
  133. <table>
  134. <tr class=' module-item'>
  135. <td><a class="trait" href="trait.ToTokens.html"
  136. title='trait quote::ToTokens'>ToTokens</a></td>
  137. <td class='docblock-short'>
  138. <p>Types that can be interpolated inside a <code>quote!(...)</code> invocation.</p>
  139. </td>
  140. </tr></table></section>
  141. <section id='search' class="content hidden"></section>
  142. <section class="footer"></section>
  143. <aside id="help" class="hidden">
  144. <div>
  145. <h1 class="hidden">Help</h1>
  146. <div class="shortcuts">
  147. <h2>Keyboard Shortcuts</h2>
  148. <dl>
  149. <dt><kbd>?</kbd></dt>
  150. <dd>Show this help dialog</dd>
  151. <dt><kbd>S</kbd></dt>
  152. <dd>Focus the search field</dd>
  153. <dt><kbd>↑</kbd></dt>
  154. <dd>Move up in search results</dd>
  155. <dt><kbd>↓</kbd></dt>
  156. <dd>Move down in search results</dd>
  157. <dt><kbd>↹</kbd></dt>
  158. <dd>Switch tab</dd>
  159. <dt><kbd>&#9166;</kbd></dt>
  160. <dd>Go to active search result</dd>
  161. <dt><kbd>+</kbd></dt>
  162. <dd>Expand all sections</dd>
  163. <dt><kbd>-</kbd></dt>
  164. <dd>Collapse all sections</dd>
  165. </dl>
  166. </div>
  167. <div class="infos">
  168. <h2>Search Tricks</h2>
  169. <p>
  170. Prefix searches with a type followed by a colon (e.g.
  171. <code>fn:</code>) to restrict the search to a given type.
  172. </p>
  173. <p>
  174. Accepted types are: <code>fn</code>, <code>mod</code>,
  175. <code>struct</code>, <code>enum</code>,
  176. <code>trait</code>, <code>type</code>, <code>macro</code>,
  177. and <code>const</code>.
  178. </p>
  179. <p>
  180. Search functions by type signature (e.g.
  181. <code>vec -> usize</code> or <code>* -> vec</code>)
  182. </p>
  183. </div>
  184. </div>
  185. </aside>
  186. <script>
  187. window.rootPath = "../";
  188. window.currentCrate = "quote";
  189. </script>
  190. <script src="../main.js"></script>
  191. <script defer src="../search-index.js"></script>
  192. </body>
  193. </html>