Auto Generated Documentation
This commit is contained in:
@@ -1,61 +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."><meta name="keywords" content="rust, rustlang, rust-lang, quote_spanned"><title>quote_spanned in quote - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><script src="../crates.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
|
||||
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
|
||||
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></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="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../quote/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class="location"><a href="index.html">quote</a></p><div id="sidebar-vars" data-name="quote_spanned" data-ty="macro" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button>
|
||||
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Macro <a href="index.html">quote</a>::<wbr><a class="macro" href="">quote_spanned</a><button id="copy-path" onclick="copy_path(this)">⎘</button></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../src/quote/lib.rs.html#586-597" title="goto source code">[src]</a></span></h1><div class="docblock type-decl"><div class="example-wrap"><pre class="rust macro">
|
||||
<span class="macro">macro_rules!</span> <span class="ident">quote_spanned</span> {
|
||||
(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">span</span>:<span class="ident">expr</span><span class="op">=</span><span class="op">></span>) <span class="op">=</span><span class="op">></span> { ... };
|
||||
(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">span</span>:<span class="ident">expr</span><span class="op">=</span><span class="op">></span> $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">tt</span>:<span class="ident">tt</span>)<span class="kw-2">*</span>) <span class="op">=</span><span class="op">></span> { ... };
|
||||
}</pre></div>
|
||||
</div><div class="docblock"><p>Same as <code>quote!</code>, but applies a given span to all tokens originating within
|
||||
<!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-46132b98.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.85.1 (4eb161250 2025-03-15)" data-channel="1.85.1" data-search-js="search-75f5ac3e.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.40</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#629-633">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>
|
||||
<h1 id="syntax" class="section-header"><a href="#syntax">Syntax</a></h1>
|
||||
<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
|
||||
<h2 id="syntax"><a class="doc-anchor" href="#syntax">§</a>Syntax</h2>
|
||||
<p>A span expression of type <a href="../proc_macro2/struct.Span.html" title="struct proc_macro2::Span"><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">
|
||||
<span class="kw">let</span> <span class="ident">span</span> <span class="op">=</span> <span class="comment">/* ... */</span>;
|
||||
<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> <span class="ident">tokens</span> <span class="op">=</span> <span class="macro">quote_spanned!</span>(<span class="ident">span</span><span class="op">=</span><span class="op">></span> <span class="ident">Box::into_raw</span>(<span class="ident">Box::new</span>(#<span class="ident">init</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> <span class="ident">tokens</span> <span class="op">=</span> <span class="macro">quote_spanned!</span> {<span class="ident">span</span><span class="op">=</span><span class="op">></span>
|
||||
<span class="ident">Box::into_raw</span>(<span class="ident">Box::new</span>(#<span class="ident">init</span>))
|
||||
};</pre></div>
|
||||
<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>
|
||||
<h1 id="hygiene" class="section-header"><a href="#hygiene">Hygiene</a></h1>
|
||||
<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>
|
||||
<h1 id="example" class="section-header"><a href="#example">Example</a></h1>
|
||||
<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
|
||||
particular Rust type implements the <a href="https://doc.rust-lang.org/1.85.1/core/marker/trait.Sync.html" title="trait core::marker::Sync"><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">
|
||||
<span class="kw">let</span> <span class="ident">ty_span</span> <span class="op">=</span> <span class="ident">ty</span>.<span class="ident">span</span>();
|
||||
<span class="kw">let</span> <span class="ident">assert_sync</span> <span class="op">=</span> <span class="macro">quote_spanned!</span> {<span class="ident">ty_span</span><span class="op">=</span><span class="op">></span>
|
||||
<span class="kw">struct</span> <span class="ident">_AssertSync</span> <span class="kw">where</span> #<span class="ident">ty</span>: <span class="ident">Sync</span>;
|
||||
};</pre></div>
|
||||
<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>
|
||||
<pre><code class="language-text">error[E0277]: the trait bound `*const (): std::marker::Sync` is not satisfied
|
||||
<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>
|
||||
| ^^^^^^^^^ `*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></section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="quote" data-search-index-js="../search-index.js" data-search-js="../search.js"></div>
|
||||
<script src="../main.js"></script></body></html>
|
||||
</div></details></section></div></main></body></html>
|
||||
Reference in New Issue
Block a user