mirror of
https://github.com/NotAShelf/mpvrc.git
synced 2026-04-19 00:59:52 +00:00
deploy: de38ae62916547ad097c066f94a32e9ba7790eeb
This commit is contained in:
commit
9a86359447
28502 changed files with 1261284 additions and 0 deletions
1
quote/all.html
Normal file
1
quote/all.html
Normal file
|
|
@ -0,0 +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="List of all items in this crate"><title>List of all items in this crate</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-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="quote" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.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 mod sys"><!--[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></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../quote/index.html">quote</a><span class="version">1.0.37</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h3><a href="#macros">Crate Items</a></h3><ul class="block"><li><a href="#macros" title="Macros">Macros</a></li><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><h1>List of all items</h1><h3 id="traits">Traits</h3><ul class="all-items"><li><a href="trait.IdentFragment.html">IdentFragment</a></li><li><a href="trait.ToTokens.html">ToTokens</a></li><li><a href="trait.TokenStreamExt.html">TokenStreamExt</a></li></ul><h3 id="macros">Macros</h3><ul class="all-items"><li><a href="macro.format_ident.html">format_ident</a></li><li><a href="macro.quote.html">quote</a></li><li><a href="macro.quote_spanned.html">quote_spanned</a></li></ul></section></div></main></body></html>
|
||||
11
quote/ext/trait.TokenStreamExt.html
Normal file
11
quote/ext/trait.TokenStreamExt.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../quote/trait.TokenStreamExt.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../quote/trait.TokenStreamExt.html">../../quote/trait.TokenStreamExt.html</a>...</p>
|
||||
<script>location.replace("../../quote/trait.TokenStreamExt.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
11
quote/ident_fragment/trait.IdentFragment.html
Normal file
11
quote/ident_fragment/trait.IdentFragment.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../quote/trait.IdentFragment.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../quote/trait.IdentFragment.html">../../quote/trait.IdentFragment.html</a>...</p>
|
||||
<script>location.replace("../../quote/trait.IdentFragment.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
57
quote/index.html
Normal file
57
quote/index.html
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<!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="github crates-io docs-rs"><title>quote - 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-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="quote" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.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 mod crate"><!--[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></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../quote/index.html">quote</a><span class="version">1.0.37</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li><li><a href="#non-macro-code-generators" title="Non-macro code generators">Non-macro code generators</a></li></ul><h3><a href="#macros">Crate Items</a></h3><ul class="block"><li><a href="#macros" title="Macros">Macros</a></li><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"></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"><h1>Crate <span>quote</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/quote/lib.rs.html#1-1464">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p><a href="https://github.com/dtolnay/quote"><img src="https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github" alt="github" /></a> <a href="https://crates.io/crates/quote"><img src="https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust" alt="crates-io" /></a> <a href="https://docs.rs/quote"><img src="https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" alt="docs-rs" /></a></p>
|
||||
<br>
|
||||
<p>This crate provides the <a href="macro.quote.html"><code>quote!</code></a> macro for turning Rust syntax tree data
|
||||
structures into tokens of source code.</p>
|
||||
<p>Procedural macros in Rust receive a stream of tokens as input, execute
|
||||
arbitrary Rust code to determine how to manipulate those tokens, and produce
|
||||
a stream of tokens to hand back to the compiler to compile into the caller’s
|
||||
crate. Quasi-quoting is a solution to one piece of that — producing
|
||||
tokens to return to the compiler.</p>
|
||||
<p>The idea of quasi-quoting is that we write <em>code</em> that we treat as <em>data</em>.
|
||||
Within the <code>quote!</code> macro, we can write what looks like code to our text
|
||||
editor or IDE. We get all the benefits of the editor’s brace matching,
|
||||
syntax highlighting, indentation, and maybe autocompletion. But rather than
|
||||
compiling that as code into the current crate, we can treat it as data, pass
|
||||
it around, mutate it, and eventually hand it back to the compiler as tokens
|
||||
to compile into the macro caller’s crate.</p>
|
||||
<p>This crate is motivated by the procedural macro use case, but is a
|
||||
general-purpose Rust quasi-quoting library and is not specific to procedural
|
||||
macros.</p>
|
||||
<div class="example-wrap"><pre class="language-toml"><code>[dependencies]
|
||||
quote = "1.0"</code></pre></div><br>
|
||||
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
|
||||
<p>The following quasi-quoted block of code is something you might find in <a href="https://serde.rs/">a</a>
|
||||
procedural macro having to do with data structure serialization. The <code>#var</code>
|
||||
syntax performs interpolation of runtime variables into the quoted tokens.
|
||||
Check out the documentation of the <a href="macro.quote.html"><code>quote!</code></a> macro for more detail about
|
||||
the syntax. See also the <a href="macro.quote_spanned.html"><code>quote_spanned!</code></a> macro which is important for
|
||||
implementing hygienic procedural macros.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>tokens = <span class="macro">quote!</span> {
|
||||
<span class="kw">struct </span>SerializeWith #generics #where_clause {
|
||||
value: <span class="kw-2">&</span><span class="lifetime">'a </span>#field_ty,
|
||||
phantom: core::marker::PhantomData<#item_ty>,
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>#generics serde::Serialize <span class="kw">for </span>SerializeWith #generics #where_clause {
|
||||
<span class="kw">fn </span>serialize<S>(<span class="kw-2">&</span><span class="self">self</span>, serializer: S) -> <span class="prelude-ty">Result</span><S::Ok, S::Error>
|
||||
<span class="kw">where
|
||||
</span>S: serde::Serializer,
|
||||
{
|
||||
#path(<span class="self">self</span>.value, serializer)
|
||||
}
|
||||
}
|
||||
|
||||
SerializeWith {
|
||||
value: #value,
|
||||
phantom: core::marker::PhantomData::<#item_ty>,
|
||||
}
|
||||
};</code></pre></div>
|
||||
<br>
|
||||
<h2 id="non-macro-code-generators"><a class="doc-anchor" href="#non-macro-code-generators">§</a>Non-macro code generators</h2>
|
||||
<p>When using <code>quote</code> in a build.rs or main.rs and writing the output out to a
|
||||
file, consider having the code generator pass the tokens through
|
||||
<a href="https://github.com/dtolnay/prettyplease">prettyplease</a> before writing. This way if an error occurs in the generated
|
||||
code it is convenient for a human to read and debug.</p>
|
||||
</div></details><h2 id="macros" class="section-header">Macros<a href="#macros" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="macro" href="macro.format_ident.html" title="macro quote::format_ident">format_<wbr>ident</a></div><div class="desc docblock-short">Formatting macro for constructing <code>Ident</code>s.</div></li><li><div class="item-name"><a class="macro" href="macro.quote.html" title="macro quote::quote">quote</a></div><div class="desc docblock-short">The whole point.</div></li><li><div class="item-name"><a class="macro" href="macro.quote_spanned.html" title="macro quote::quote_spanned">quote_<wbr>spanned</a></div><div class="desc docblock-short">Same as <code>quote!</code>, but applies a given span to all tokens originating within
|
||||
the macro invocation.</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.IdentFragment.html" title="trait quote::IdentFragment">Ident<wbr>Fragment</a></div><div class="desc docblock-short">Specialized formatting trait used by <code>format_ident!</code>.</div></li><li><div class="item-name"><a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a></div><div class="desc docblock-short">Types that can be interpolated inside a <code>quote!</code> invocation.</div></li><li><div class="item-name"><a class="trait" href="trait.TokenStreamExt.html" title="trait quote::TokenStreamExt">Token<wbr>Stream<wbr>Ext</a></div><div class="desc docblock-short">TokenStream extension trait with methods for appending tokens.</div></li></ul></section></div></main></body></html>
|
||||
11
quote/macro.format_ident!.html
Normal file
11
quote/macro.format_ident!.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=macro.format_ident.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="macro.format_ident.html">macro.format_ident.html</a>...</p>
|
||||
<script>location.replace("macro.format_ident.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
76
quote/macro.format_ident.html
Normal file
76
quote/macro.format_ident.html
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<!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="Formatting macro for constructing `Ident`s."><title>format_ident in quote - 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-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="quote" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.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></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../quote/index.html">quote</a><span class="version">1.0.37</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">format_<wbr>ident</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#syntax" title="Syntax">Syntax</a></li><li><a href="#identfragment" title="IdentFragment">IdentFragment</a></li><li><a href="#hygiene" title="Hygiene">Hygiene</a></li><li><a href="#panics" title="Panics">Panics</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate quote</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">quote</a></span><h1>Macro <span class="macro">format_ident</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/quote/format.rs.html#111-125">Source</a> </span></div><pre class="rust item-decl"><code>macro_rules! format_ident {
|
||||
($fmt:expr) => { ... };
|
||||
($fmt:expr, $($rest:tt)*) => { ... };
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Formatting macro for constructing <code>Ident</code>s.</p>
|
||||
<br>
|
||||
<h2 id="syntax"><a class="doc-anchor" href="#syntax">§</a>Syntax</h2>
|
||||
<p>Syntax is copied from the <a href="https://doc.rust-lang.org/1.84.1/alloc/macro.format.html" title="macro alloc::format"><code>format!</code></a> macro, supporting both positional and
|
||||
named arguments.</p>
|
||||
<p>Only a limited set of formatting traits are supported. The current mapping
|
||||
of format types to traits is:</p>
|
||||
<ul>
|
||||
<li><code>{}</code> ⇒ <a href="trait.IdentFragment.html" title="trait quote::IdentFragment"><code>IdentFragment</code></a></li>
|
||||
<li><code>{:o}</code> ⇒ <a href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.Octal.html" title="trait core::fmt::Octal"><code>Octal</code></a></li>
|
||||
<li><code>{:x}</code> ⇒ <a href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.LowerHex.html" title="trait core::fmt::LowerHex"><code>LowerHex</code></a></li>
|
||||
<li><code>{:X}</code> ⇒ <a href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.UpperHex.html" title="trait core::fmt::UpperHex"><code>UpperHex</code></a></li>
|
||||
<li><code>{:b}</code> ⇒ <a href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.Binary.html" title="trait core::fmt::Binary"><code>Binary</code></a></li>
|
||||
</ul>
|
||||
<p>See <a href="https://doc.rust-lang.org/1.84.1/alloc/fmt/index.html" title="mod alloc::fmt"><code>std::fmt</code></a> for more information.</p>
|
||||
<br>
|
||||
<h2 id="identfragment"><a class="doc-anchor" href="#identfragment">§</a>IdentFragment</h2>
|
||||
<p>Unlike <code>format!</code>, this macro uses the <a href="trait.IdentFragment.html" title="trait quote::IdentFragment"><code>IdentFragment</code></a> formatting trait by
|
||||
default. This trait is like <code>Display</code>, with a few differences:</p>
|
||||
<ul>
|
||||
<li><code>IdentFragment</code> is only implemented for a limited set of types, such as
|
||||
unsigned integers and strings.</li>
|
||||
<li><a href="../proc_macro2/struct.Ident.html" title="struct proc_macro2::Ident"><code>Ident</code></a> arguments will have their <code>r#</code> prefixes stripped, if present.</li>
|
||||
</ul>
|
||||
<br>
|
||||
<h2 id="hygiene"><a class="doc-anchor" href="#hygiene">§</a>Hygiene</h2>
|
||||
<p>The <a href="../proc_macro2/struct.Span.html" title="struct proc_macro2::Span"><code>Span</code></a> of the first <code>Ident</code> argument is used as the span of the final
|
||||
identifier, falling back to <a href="../proc_macro2/struct.Span.html#method.call_site" title="associated function proc_macro2::Span::call_site"><code>Span::call_site</code></a> when no identifiers are
|
||||
provided.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// If `ident` is an Ident, the span of `my_ident` will be inherited from it.
|
||||
</span><span class="kw">let </span>my_ident = <span class="macro">format_ident!</span>(<span class="string">"My{}{}"</span>, ident, <span class="string">"IsCool"</span>);
|
||||
<span class="macro">assert_eq!</span>(my_ident, <span class="string">"MyIdentIsCool"</span>);</code></pre></div>
|
||||
<p>Alternatively, the span can be overridden by passing the <code>span</code> named
|
||||
argument.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>my_span = <span class="comment">/* ... */</span>;
|
||||
<span class="macro">format_ident!</span>(<span class="string">"MyIdent"</span>, span = my_span);</code></pre></div>
|
||||
<p><br></p>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>This method will panic if the resulting formatted string is not a valid
|
||||
identifier.</p>
|
||||
<br>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>Composing raw and non-raw identifiers:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>my_ident = <span class="macro">format_ident!</span>(<span class="string">"My{}"</span>, <span class="string">"Ident"</span>);
|
||||
<span class="macro">assert_eq!</span>(my_ident, <span class="string">"MyIdent"</span>);
|
||||
|
||||
<span class="kw">let </span>raw = <span class="macro">format_ident!</span>(<span class="string">"r#Raw"</span>);
|
||||
<span class="macro">assert_eq!</span>(raw, <span class="string">"r#Raw"</span>);
|
||||
|
||||
<span class="kw">let </span>my_ident_raw = <span class="macro">format_ident!</span>(<span class="string">"{}Is{}"</span>, my_ident, raw);
|
||||
<span class="macro">assert_eq!</span>(my_ident_raw, <span class="string">"MyIdentIsRaw"</span>);</code></pre></div>
|
||||
<p>Integer formatting options:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>num: u32 = <span class="number">10</span>;
|
||||
|
||||
<span class="kw">let </span>decimal = <span class="macro">format_ident!</span>(<span class="string">"Id_{}"</span>, num);
|
||||
<span class="macro">assert_eq!</span>(decimal, <span class="string">"Id_10"</span>);
|
||||
|
||||
<span class="kw">let </span>octal = <span class="macro">format_ident!</span>(<span class="string">"Id_{:o}"</span>, num);
|
||||
<span class="macro">assert_eq!</span>(octal, <span class="string">"Id_12"</span>);
|
||||
|
||||
<span class="kw">let </span>binary = <span class="macro">format_ident!</span>(<span class="string">"Id_{:b}"</span>, num);
|
||||
<span class="macro">assert_eq!</span>(binary, <span class="string">"Id_1010"</span>);
|
||||
|
||||
<span class="kw">let </span>lower_hex = <span class="macro">format_ident!</span>(<span class="string">"Id_{:x}"</span>, num);
|
||||
<span class="macro">assert_eq!</span>(lower_hex, <span class="string">"Id_a"</span>);
|
||||
|
||||
<span class="kw">let </span>upper_hex = <span class="macro">format_ident!</span>(<span class="string">"Id_{:X}"</span>, num);
|
||||
<span class="macro">assert_eq!</span>(upper_hex, <span class="string">"Id_A"</span>);</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
11
quote/macro.quote!.html
Normal file
11
quote/macro.quote!.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=macro.quote.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="macro.quote.html">macro.quote.html</a>...</p>
|
||||
<script>location.replace("macro.quote.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
189
quote/macro.quote.html
Normal file
189
quote/macro.quote.html
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
<!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="The whole point."><title>quote in quote - 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-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="quote" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.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></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../quote/index.html">quote</a><span class="version">1.0.37</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">quote</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#interpolation" title="Interpolation">Interpolation</a></li><li><a href="#hygiene" title="Hygiene">Hygiene</a></li><li><a href="#return-type" title="Return type">Return type</a></li><li><a href="#examples" title="Examples">Examples</a><ul><li><a href="#procedural-macro" title="Procedural macro">Procedural macro</a></li><li><a href="#combining-quoted-fragments" title="Combining quoted fragments">Combining quoted fragments</a></li><li><a href="#constructing-identifiers" title="Constructing identifiers">Constructing identifiers</a></li><li><a href="#making-method-calls" title="Making method calls">Making method calls</a></li><li><a href="#interpolating-text-inside-of-doc-comments" title="Interpolating text inside of doc comments">Interpolating text inside of doc comments</a></li><li><a href="#indexing-into-a-tuple-struct" title="Indexing into a tuple struct">Indexing into a tuple struct</a></li></ul></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate quote</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">quote</a></span><h1>Macro <span class="macro">quote</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/quote/lib.rs.html#490-494">Source</a> </span></div><pre class="rust item-decl"><code>macro_rules! quote {
|
||||
($($tt:tt)*) => { ... };
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>The whole point.</p>
|
||||
<p>Performs variable interpolation against the input and produces it as
|
||||
<a href="../proc_macro2/struct.TokenStream.html" title="struct proc_macro2::TokenStream"><code>proc_macro2::TokenStream</code></a>.</p>
|
||||
<p>Note: for returning tokens to the compiler in a procedural macro, use
|
||||
<code>.into()</code> on the result to convert to <a href="https://doc.rust-lang.org/1.84.1/proc_macro/struct.TokenStream.html" title="struct proc_macro::TokenStream"><code>proc_macro::TokenStream</code></a>.</p>
|
||||
<br>
|
||||
<h2 id="interpolation"><a class="doc-anchor" href="#interpolation">§</a>Interpolation</h2>
|
||||
<p>Variable interpolation is done with <code>#var</code> (similar to <code>$var</code> in
|
||||
<code>macro_rules!</code> macros). This grabs the <code>var</code> variable that is currently in
|
||||
scope and inserts it in that location in the output tokens. Any type
|
||||
implementing the <a href="trait.ToTokens.html"><code>ToTokens</code></a> trait can be interpolated. This includes most
|
||||
Rust primitive types as well as most of the syntax tree types from the <a href="https://github.com/dtolnay/syn">Syn</a>
|
||||
crate.</p>
|
||||
<p>Repetition is done using <code>#(...)*</code> or <code>#(...),*</code> again similar to
|
||||
<code>macro_rules!</code>. This iterates through the elements of any variable
|
||||
interpolated within the repetition and inserts a copy of the repetition body
|
||||
for each one. The variables in an interpolation may be a <code>Vec</code>, slice,
|
||||
<code>BTreeSet</code>, or any <code>Iterator</code>.</p>
|
||||
<ul>
|
||||
<li><code>#(#var)*</code> — no separators</li>
|
||||
<li><code>#(#var),*</code> — the character before the asterisk is used as a separator</li>
|
||||
<li><code>#( struct #var; )*</code> — the repetition can contain other tokens</li>
|
||||
<li><code>#( #k => println!("{}", #v), )*</code> — even multiple interpolations</li>
|
||||
</ul>
|
||||
<br>
|
||||
<h2 id="hygiene"><a class="doc-anchor" href="#hygiene">§</a>Hygiene</h2>
|
||||
<p>Any interpolated tokens preserve the <code>Span</code> information provided by their
|
||||
<code>ToTokens</code> implementation. Tokens that originate within the <code>quote!</code>
|
||||
invocation are spanned with <a href="https://docs.rs/proc-macro2/1.0/proc_macro2/struct.Span.html#method.call_site"><code>Span::call_site()</code></a>.</p>
|
||||
<p>A different span can be provided through the <a href="macro.quote_spanned.html"><code>quote_spanned!</code></a> macro.</p>
|
||||
<br>
|
||||
<h2 id="return-type"><a class="doc-anchor" href="#return-type">§</a>Return type</h2>
|
||||
<p>The macro evaluates to an expression of type <code>proc_macro2::TokenStream</code>.
|
||||
Meanwhile Rust procedural macros are expected to return the type
|
||||
<code>proc_macro::TokenStream</code>.</p>
|
||||
<p>The difference between the two types is that <code>proc_macro</code> types are entirely
|
||||
specific to procedural macros and cannot ever exist in code outside of a
|
||||
procedural macro, while <code>proc_macro2</code> types may exist anywhere including
|
||||
tests and non-macro code like main.rs and build.rs. This is why even the
|
||||
procedural macro ecosystem is largely built around <code>proc_macro2</code>, because
|
||||
that ensures the libraries are unit testable and accessible in non-macro
|
||||
contexts.</p>
|
||||
<p>There is a <a href="https://doc.rust-lang.org/std/convert/trait.From.html"><code>From</code></a>-conversion in both directions so returning the output of
|
||||
<code>quote!</code> from a procedural macro usually looks like <code>tokens.into()</code> or
|
||||
<code>proc_macro::TokenStream::from(tokens)</code>.</p>
|
||||
<br>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2><h4 id="procedural-macro"><a class="doc-anchor" href="#procedural-macro">§</a>Procedural macro</h4>
|
||||
<p>The structure of a basic procedural macro is as follows. Refer to the <a href="https://github.com/dtolnay/syn">Syn</a>
|
||||
crate for further useful guidance on using <code>quote!</code> as part of a procedural
|
||||
macro.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">extern crate </span>proc_macro;
|
||||
|
||||
<span class="kw">use </span>proc_macro::TokenStream;
|
||||
<span class="kw">use </span>quote::quote;
|
||||
|
||||
<span class="attr">#[proc_macro_derive(HeapSize)]
|
||||
</span><span class="kw">pub fn </span>derive_heap_size(input: TokenStream) -> TokenStream {
|
||||
<span class="comment">// Parse the input and figure out what implementation to generate...
|
||||
</span><span class="kw">let </span>name = <span class="comment">/* ... */</span>;
|
||||
<span class="kw">let </span>expr = <span class="comment">/* ... */</span>;
|
||||
|
||||
<span class="kw">let </span>expanded = <span class="macro">quote!</span> {
|
||||
<span class="comment">// The generated impl.
|
||||
</span><span class="kw">impl </span>heapsize::HeapSize <span class="kw">for </span>#name {
|
||||
<span class="kw">fn </span>heap_size_of_children(<span class="kw-2">&</span><span class="self">self</span>) -> usize {
|
||||
#expr
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
<span class="comment">// Hand the output tokens back to the compiler.
|
||||
</span>TokenStream::from(expanded)
|
||||
}</code></pre></div>
|
||||
<p><br></p>
|
||||
<h4 id="combining-quoted-fragments"><a class="doc-anchor" href="#combining-quoted-fragments">§</a>Combining quoted fragments</h4>
|
||||
<p>Usually you don’t end up constructing an entire final <code>TokenStream</code> in one
|
||||
piece. Different parts may come from different helper functions. The tokens
|
||||
produced by <code>quote!</code> themselves implement <code>ToTokens</code> and so can be
|
||||
interpolated into later <code>quote!</code> invocations to build up a final result.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>type_definition = <span class="macro">quote!</span> {...};
|
||||
<span class="kw">let </span>methods = <span class="macro">quote!</span> {...};
|
||||
|
||||
<span class="kw">let </span>tokens = <span class="macro">quote!</span> {
|
||||
#type_definition
|
||||
#methods
|
||||
};</code></pre></div>
|
||||
<p><br></p>
|
||||
<h4 id="constructing-identifiers"><a class="doc-anchor" href="#constructing-identifiers">§</a>Constructing identifiers</h4>
|
||||
<p>Suppose we have an identifier <code>ident</code> which came from somewhere in a macro
|
||||
input and we need to modify it in some way for the macro output. Let’s
|
||||
consider prepending the identifier with an underscore.</p>
|
||||
<p>Simply interpolating the identifier next to an underscore will not have the
|
||||
behavior of concatenating them. The underscore and the identifier will
|
||||
continue to be two separate tokens as if you had written <code>_ x</code>.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// incorrect
|
||||
</span><span class="macro">quote!</span> {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>_#ident = <span class="number">0</span>;
|
||||
}</code></pre></div>
|
||||
<p>The solution is to build a new identifier token with the correct value. As
|
||||
this is such a common case, the <a href="macro.format_ident.html" title="macro quote::format_ident"><code>format_ident!</code></a> macro provides a
|
||||
convenient utility for doing so correctly.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>varname = <span class="macro">format_ident!</span>(<span class="string">"_{}"</span>, ident);
|
||||
<span class="macro">quote!</span> {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>#varname = <span class="number">0</span>;
|
||||
}</code></pre></div>
|
||||
<p>Alternatively, the APIs provided by Syn and proc-macro2 can be used to
|
||||
directly build the identifier. This is roughly equivalent to the above, but
|
||||
will not handle <code>ident</code> being a raw identifier.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>concatenated = <span class="macro">format!</span>(<span class="string">"_{}"</span>, ident);
|
||||
<span class="kw">let </span>varname = syn::Ident::new(<span class="kw-2">&</span>concatenated, ident.span());
|
||||
<span class="macro">quote!</span> {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>#varname = <span class="number">0</span>;
|
||||
}</code></pre></div>
|
||||
<p><br></p>
|
||||
<h4 id="making-method-calls"><a class="doc-anchor" href="#making-method-calls">§</a>Making method calls</h4>
|
||||
<p>Let’s say our macro requires some type specified in the macro input to have
|
||||
a constructor called <code>new</code>. We have the type in a variable called
|
||||
<code>field_type</code> of type <code>syn::Type</code> and want to invoke the constructor.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// incorrect
|
||||
</span><span class="macro">quote!</span> {
|
||||
<span class="kw">let </span>value = #field_type::new();
|
||||
}</code></pre></div>
|
||||
<p>This works only sometimes. If <code>field_type</code> is <code>String</code>, the expanded code
|
||||
contains <code>String::new()</code> which is fine. But if <code>field_type</code> is something
|
||||
like <code>Vec<i32></code> then the expanded code is <code>Vec<i32>::new()</code> which is invalid
|
||||
syntax. Ordinarily in handwritten Rust we would write <code>Vec::<i32>::new()</code>
|
||||
but for macros often the following is more convenient.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">quote!</span> {
|
||||
<span class="kw">let </span>value = <#field_type>::new();
|
||||
}</code></pre></div>
|
||||
<p>This expands to <code><Vec<i32>>::new()</code> which behaves correctly.</p>
|
||||
<p>A similar pattern is appropriate for trait methods.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">quote!</span> {
|
||||
<span class="kw">let </span>value = <#field_type <span class="kw">as </span>core::default::Default>::default();
|
||||
}</code></pre></div>
|
||||
<p><br></p>
|
||||
<h4 id="interpolating-text-inside-of-doc-comments"><a class="doc-anchor" href="#interpolating-text-inside-of-doc-comments">§</a>Interpolating text inside of doc comments</h4>
|
||||
<p>Neither doc comments nor string literals get interpolation behavior in
|
||||
quote:</p>
|
||||
|
||||
<div class="example-wrap compile_fail"><a href="#" class="tooltip" title="This example deliberately fails to compile">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="macro">quote!</span> {
|
||||
<span class="doccomment">/// try to interpolate: #ident
|
||||
///
|
||||
/// ...
|
||||
</span>}</code></pre></div>
|
||||
|
||||
<div class="example-wrap compile_fail"><a href="#" class="tooltip" title="This example deliberately fails to compile">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="macro">quote!</span> {
|
||||
<span class="attr">#[doc = <span class="string">"try to interpolate: #ident"</span>]
|
||||
</span>}</code></pre></div>
|
||||
<p>Instead the best way to build doc comments that involve variables is by
|
||||
formatting the doc string literal outside of quote.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>msg = <span class="macro">format!</span>(...);
|
||||
<span class="macro">quote!</span> {
|
||||
<span class="attr">#[doc = #msg]
|
||||
</span><span class="doccomment">///
|
||||
/// ...
|
||||
</span>}</code></pre></div>
|
||||
<p><br></p>
|
||||
<h4 id="indexing-into-a-tuple-struct"><a class="doc-anchor" href="#indexing-into-a-tuple-struct">§</a>Indexing into a tuple struct</h4>
|
||||
<p>When interpolating indices of a tuple or tuple struct, we need them not to
|
||||
appears suffixed as integer literals by interpolating them as <a href="https://docs.rs/syn/2.0/syn/struct.Index.html"><code>syn::Index</code></a>
|
||||
instead.</p>
|
||||
|
||||
<div class="example-wrap compile_fail"><a href="#" class="tooltip" title="This example deliberately fails to compile">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">let </span>i = <span class="number">0usize</span>..<span class="self">self</span>.fields.len();
|
||||
|
||||
<span class="comment">// expands to 0 + self.0usize.heap_size() + self.1usize.heap_size() + ...
|
||||
// which is not valid syntax
|
||||
</span><span class="macro">quote!</span> {
|
||||
<span class="number">0 </span>#( + <span class="self">self</span>.#i.heap_size() )*
|
||||
}</code></pre></div>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>i = (<span class="number">0</span>..<span class="self">self</span>.fields.len()).map(syn::Index::from);
|
||||
|
||||
<span class="comment">// expands to 0 + self.0.heap_size() + self.1.heap_size() + ...
|
||||
</span><span class="macro">quote!</span> {
|
||||
<span class="number">0 </span>#( + <span class="self">self</span>.#i.heap_size() )*
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
11
quote/macro.quote_spanned!.html
Normal file
11
quote/macro.quote_spanned!.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=macro.quote_spanned.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="macro.quote_spanned.html">macro.quote_spanned.html</a>...</p>
|
||||
<script>location.replace("macro.quote_spanned.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
51
quote/macro.quote_spanned.html
Normal file
51
quote/macro.quote_spanned.html
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<!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="Same as `quote!`, but applies a given span to all tokens originating within the macro invocation."><title>quote_spanned in quote - 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-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="quote" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.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></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../quote/index.html">quote</a><span class="version">1.0.37</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">quote_<wbr>spanned</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#syntax" title="Syntax">Syntax</a></li><li><a href="#hygiene" title="Hygiene">Hygiene</a></li><li><a href="#example" title="Example">Example</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate quote</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">quote</a></span><h1>Macro <span class="macro">quote_spanned</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/quote/lib.rs.html#639-643">Source</a> </span></div><pre class="rust item-decl"><code>macro_rules! quote_spanned {
|
||||
($span:expr=> $($tt:tt)*) => { ... };
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Same as <code>quote!</code>, but applies a given span to all tokens originating within
|
||||
the macro invocation.</p>
|
||||
<br>
|
||||
<h2 id="syntax"><a class="doc-anchor" href="#syntax">§</a>Syntax</h2>
|
||||
<p>A span expression of type <a href="https://docs.rs/proc-macro2/1.0/proc_macro2/struct.Span.html"><code>Span</code></a>, followed by <code>=></code>, followed by the tokens
|
||||
to quote. The span expression should be brief — use a variable for
|
||||
anything more than a few characters. There should be no space before the
|
||||
<code>=></code> token.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>span = <span class="comment">/* ... */</span>;
|
||||
|
||||
<span class="comment">// On one line, use parentheses.
|
||||
</span><span class="kw">let </span>tokens = <span class="macro">quote_spanned!</span>(span=> Box::into_raw(Box::new(#init)));
|
||||
|
||||
<span class="comment">// On multiple lines, place the span at the top and use braces.
|
||||
</span><span class="kw">let </span>tokens = <span class="macro">quote_spanned!</span> {span=>
|
||||
Box::into_raw(Box::new(#init))
|
||||
};</code></pre></div>
|
||||
<p>The lack of space before the <code>=></code> should look jarring to Rust programmers
|
||||
and this is intentional. The formatting is designed to be visibly
|
||||
off-balance and draw the eye a particular way, due to the span expression
|
||||
being evaluated in the context of the procedural macro and the remaining
|
||||
tokens being evaluated in the generated code.</p>
|
||||
<br>
|
||||
<h2 id="hygiene"><a class="doc-anchor" href="#hygiene">§</a>Hygiene</h2>
|
||||
<p>Any interpolated tokens preserve the <code>Span</code> information provided by their
|
||||
<code>ToTokens</code> implementation. Tokens that originate within the <code>quote_spanned!</code>
|
||||
invocation are spanned with the given span argument.</p>
|
||||
<br>
|
||||
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
|
||||
<p>The following procedural macro code uses <code>quote_spanned!</code> to assert that a
|
||||
particular Rust type implements the <a href="https://doc.rust-lang.org/std/marker/trait.Sync.html"><code>Sync</code></a> trait so that references can be
|
||||
safely shared between threads.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>ty_span = ty.span();
|
||||
<span class="kw">let </span>assert_sync = <span class="macro">quote_spanned!</span> {ty_span=>
|
||||
<span class="kw">struct </span>_AssertSync <span class="kw">where </span>#ty: Sync;
|
||||
};</code></pre></div>
|
||||
<p>If the assertion fails, the user will see an error like the following. The
|
||||
input span of their type is highlighted in the error.</p>
|
||||
<div class="example-wrap"><pre class="language-text"><code>error[E0277]: the trait bound `*const (): std::marker::Sync` is not satisfied
|
||||
--> src/main.rs:10:21
|
||||
|
|
||||
10 | static ref PTR: *const () = &();
|
||||
| ^^^^^^^^^ `*const ()` cannot be shared between threads safely</code></pre></div>
|
||||
<p>In this example it is important for the where-clause to be spanned with the
|
||||
line/column information of the user’s input type so that error messages are
|
||||
placed appropriately by the compiler.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
1
quote/sidebar-items.js
Normal file
1
quote/sidebar-items.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
window.SIDEBAR_ITEMS = {"macro":["format_ident","quote","quote_spanned"],"trait":["IdentFragment","ToTokens","TokenStreamExt"]};
|
||||
11
quote/to_tokens/trait.ToTokens.html
Normal file
11
quote/to_tokens/trait.ToTokens.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../quote/trait.ToTokens.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../quote/trait.ToTokens.html">../../quote/trait.ToTokens.html</a>...</p>
|
||||
<script>location.replace("../../quote/trait.ToTokens.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
15
quote/trait.IdentFragment.html
Normal file
15
quote/trait.IdentFragment.html
Normal file
File diff suppressed because one or more lines are too long
44
quote/trait.ToTokens.html
Normal file
44
quote/trait.ToTokens.html
Normal file
File diff suppressed because one or more lines are too long
56
quote/trait.TokenStreamExt.html
Normal file
56
quote/trait.TokenStreamExt.html
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<!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="TokenStream extension trait with methods for appending tokens."><title>TokenStreamExt in quote - 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-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="quote" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.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 trait"><!--[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></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../quote/index.html">quote</a><span class="version">1.0.37</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Token<wbr>Stream<wbr>Ext</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.append" title="append">append</a></li><li><a href="#tymethod.append_all" title="append_all">append_all</a></li><li><a href="#tymethod.append_separated" title="append_separated">append_separated</a></li><li><a href="#tymethod.append_terminated" title="append_terminated">append_terminated</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-TokenStreamExt-for-TokenStream" title="TokenStream">TokenStream</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate quote</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">quote</a></span><h1>Trait <span class="trait">TokenStreamExt</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/quote/ext.rs.html#8-57">Source</a> </span></div><pre class="rust item-decl"><code>pub trait TokenStreamExt: Sealed {
|
||||
// Required methods
|
||||
fn <a href="#tymethod.append" class="fn">append</a><U>(&mut self, token: U)
|
||||
<span class="where">where U: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="enum" href="../proc_macro2/enum.TokenTree.html" title="enum proc_macro2::TokenTree">TokenTree</a>></span>;
|
||||
<span class="item-spacer"></span> fn <a href="#tymethod.append_all" class="fn">append_all</a><I>(&mut self, iter: I)
|
||||
<span class="where">where I: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
||||
I::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a></span>;
|
||||
<span class="item-spacer"></span> fn <a href="#tymethod.append_separated" class="fn">append_separated</a><I, U>(&mut self, iter: I, op: U)
|
||||
<span class="where">where I: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
||||
I::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a>,
|
||||
U: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a></span>;
|
||||
<span class="item-spacer"></span> fn <a href="#tymethod.append_terminated" class="fn">append_terminated</a><I, U>(&mut self, iter: I, term: U)
|
||||
<span class="where">where I: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
||||
I::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a>,
|
||||
U: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a></span>;
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>TokenStream extension trait with methods for appending tokens.</p>
|
||||
<p>This trait is sealed and cannot be implemented outside of the <code>quote</code> crate.</p>
|
||||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.append" class="method"><a class="src rightside" href="../src/quote/ext.rs.html#12-14">Source</a><h4 class="code-header">fn <a href="#tymethod.append" class="fn">append</a><U>(&mut self, token: U)<div class="where">where
|
||||
U: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="enum" href="../proc_macro2/enum.TokenTree.html" title="enum proc_macro2::TokenTree">TokenTree</a>>,</div></h4></section></summary><div class="docblock"><p>For use by <code>ToTokens</code> implementations.</p>
|
||||
<p>Appends the token specified to this list of tokens.</p>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.append_all" class="method"><a class="src rightside" href="../src/quote/ext.rs.html#33-36">Source</a><h4 class="code-header">fn <a href="#tymethod.append_all" class="fn">append_all</a><I>(&mut self, iter: I)<div class="where">where
|
||||
I: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
||||
I::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a>,</div></h4></section></summary><div class="docblock"><p>For use by <code>ToTokens</code> implementations.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">struct </span>X;
|
||||
|
||||
<span class="kw">impl </span>ToTokens <span class="kw">for </span>X {
|
||||
<span class="kw">fn </span>to_tokens(<span class="kw-2">&</span><span class="self">self</span>, tokens: <span class="kw-2">&mut </span>TokenStream) {
|
||||
tokens.append_all(<span class="kw-2">&</span>[<span class="bool-val">true</span>, <span class="bool-val">false</span>]);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">let </span>tokens = <span class="macro">quote!</span>(#X);
|
||||
<span class="macro">assert_eq!</span>(tokens.to_string(), <span class="string">"true false"</span>);</code></pre></div>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.append_separated" class="method"><a class="src rightside" href="../src/quote/ext.rs.html#42-46">Source</a><h4 class="code-header">fn <a href="#tymethod.append_separated" class="fn">append_separated</a><I, U>(&mut self, iter: I, op: U)<div class="where">where
|
||||
I: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
||||
I::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a>,
|
||||
U: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a>,</div></h4></section></summary><div class="docblock"><p>For use by <code>ToTokens</code> implementations.</p>
|
||||
<p>Appends all of the items in the iterator <code>I</code>, separated by the tokens
|
||||
<code>U</code>.</p>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.append_terminated" class="method"><a class="src rightside" href="../src/quote/ext.rs.html#52-56">Source</a><h4 class="code-header">fn <a href="#tymethod.append_terminated" class="fn">append_terminated</a><I, U>(&mut self, iter: I, term: U)<div class="where">where
|
||||
I: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
||||
I::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a>,
|
||||
U: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a>,</div></h4></section></summary><div class="docblock"><p>For use by <code>ToTokens</code> implementations.</p>
|
||||
<p>Appends all tokens in the iterator <code>I</code>, appending <code>U</code> after each
|
||||
element, including after the last element of the iterator.</p>
|
||||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.1/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-TokenStreamExt-for-TokenStream" class="impl"><a class="src rightside" href="../src/quote/ext.rs.html#59-102">Source</a><a href="#impl-TokenStreamExt-for-TokenStream" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.TokenStreamExt.html" title="trait quote::TokenStreamExt">TokenStreamExt</a> for <a class="struct" href="../proc_macro2/struct.TokenStream.html" title="struct proc_macro2::TokenStream">TokenStream</a></h3></section></summary><div class="impl-items"><section id="method.append" class="method trait-impl"><a class="src rightside" href="../src/quote/ext.rs.html#60-65">Source</a><a href="#method.append" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.append" class="fn">append</a><U>(&mut self, token: U)<div class="where">where
|
||||
U: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="enum" href="../proc_macro2/enum.TokenTree.html" title="enum proc_macro2::TokenTree">TokenTree</a>>,</div></h4></section><section id="method.append_all" class="method trait-impl"><a class="src rightside" href="../src/quote/ext.rs.html#67-75">Source</a><a href="#method.append_all" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.append_all" class="fn">append_all</a><I>(&mut self, iter: I)<div class="where">where
|
||||
I: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
||||
I::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a>,</div></h4></section><section id="method.append_separated" class="method trait-impl"><a class="src rightside" href="../src/quote/ext.rs.html#77-89">Source</a><a href="#method.append_separated" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.append_separated" class="fn">append_separated</a><I, U>(&mut self, iter: I, op: U)<div class="where">where
|
||||
I: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
||||
I::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a>,
|
||||
U: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a>,</div></h4></section><section id="method.append_terminated" class="method trait-impl"><a class="src rightside" href="../src/quote/ext.rs.html#91-101">Source</a><a href="#method.append_terminated" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.append_terminated" class="fn">append_terminated</a><I, U>(&mut self, iter: I, term: U)<div class="where">where
|
||||
I: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,
|
||||
I::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a>,
|
||||
U: <a class="trait" href="trait.ToTokens.html" title="trait quote::ToTokens">ToTokens</a>,</div></h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../trait.impl/quote/ext/trait.TokenStreamExt.js" data-ignore-extern-crates="proc_macro2" async></script></section></div></main></body></html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue