rtic/1/api/syn/token/index.html

64 lines
26 KiB
HTML
Raw Normal View History

<!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="Tokens representing Rust punctuation, keywords, and delimiters."><title>syn::token - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.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-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b0742ba02757f159.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="syn" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0 (90b35a623 2024-11-26)" data-channel="1.83.0" data-search-js="search-f0d225181b97f9a4.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-f070b9041d14864c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod"><!--[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="../../syn/index.html">syn</a><span class="version">1.0.109</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module token</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li><li><a href="#parsing" title="Parsing">Parsing</a></li><li><a href="#other-operations" title="Other operations">Other operations</a></li></ul><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate syn</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">syn</a></span><h1>Module <span>token</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/syn/token.rs.html#1-1013">source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Tokens representing Rust punctuation, keywords, and delimiters.</p>
<p>The type names in this module can be difficult to keep straight, so we
prefer to use the <a href="../macro.Token.html" title="macro syn::Token"><code>Token!</code></a> macro instead. This is a type-macro that
expands to the token type of the given token.</p>
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
<p>The <a href="../struct.ItemStatic.html" title="struct syn::ItemStatic"><code>ItemStatic</code></a> syntax tree node is defined like this.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">pub struct </span>ItemStatic {
<span class="kw">pub </span>attrs: Vec&lt;Attribute&gt;,
<span class="kw">pub </span>vis: Visibility,
<span class="kw">pub </span>static_token: <span class="macro">Token!</span>[<span class="kw">static</span>],
<span class="kw">pub </span>mutability: <span class="prelude-ty">Option</span>&lt;<span class="macro">Token!</span>[<span class="kw-2">mut</span>]&gt;,
<span class="kw">pub </span>ident: Ident,
<span class="kw">pub </span>colon_token: <span class="macro">Token!</span>[:],
<span class="kw">pub </span>ty: Box&lt;Type&gt;,
<span class="kw">pub </span>eq_token: <span class="macro">Token!</span>[=],
<span class="kw">pub </span>expr: Box&lt;Expr&gt;,
<span class="kw">pub </span>semi_token: <span class="macro">Token!</span>[;],
}</code></pre></div>
<h2 id="parsing"><a class="doc-anchor" href="#parsing">§</a>Parsing</h2>
<p>Keywords and punctuation can be parsed through the <a href="../parse/struct.ParseBuffer.html#method.parse" title="method syn::parse::ParseBuffer::parse"><code>ParseStream::parse</code></a>
method. Delimiter tokens are parsed using the <a href="../macro.parenthesized.html" title="macro syn::parenthesized"><code>parenthesized!</code></a>,
<a href="../macro.bracketed.html" title="macro syn::bracketed"><code>bracketed!</code></a> and <a href="../macro.braced.html" title="macro syn::braced"><code>braced!</code></a> macros.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>syn::{Attribute, <span class="prelude-ty">Result</span>};
<span class="kw">use </span>syn::parse::{Parse, ParseStream};
<span class="comment">// Parse the ItemStatic struct shown above.
</span><span class="kw">impl </span>Parse <span class="kw">for </span>ItemStatic {
<span class="kw">fn </span>parse(input: ParseStream) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>&gt; {
<span class="prelude-val">Ok</span>(ItemStatic {
attrs: input.call(Attribute::parse_outer)<span class="question-mark">?</span>,
vis: input.parse()<span class="question-mark">?</span>,
static_token: input.parse()<span class="question-mark">?</span>,
mutability: input.parse()<span class="question-mark">?</span>,
ident: input.parse()<span class="question-mark">?</span>,
colon_token: input.parse()<span class="question-mark">?</span>,
ty: input.parse()<span class="question-mark">?</span>,
eq_token: input.parse()<span class="question-mark">?</span>,
expr: input.parse()<span class="question-mark">?</span>,
semi_token: input.parse()<span class="question-mark">?</span>,
})
}
}</code></pre></div>
<h2 id="other-operations"><a class="doc-anchor" href="#other-operations">§</a>Other operations</h2>
<p>Every keyword and punctuation token supports the following operations.</p>
<ul>
<li>
<p><a href="../parse/struct.ParseBuffer.html#method.peek" title="method syn::parse::ParseBuffer::peek">Peeking</a><code>input.peek(Token![...])</code></p>
</li>
<li>
<p><a href="../parse/struct.ParseBuffer.html#method.parse" title="method syn::parse::ParseBuffer::parse">Parsing</a><code>input.parse::&lt;Token![...]&gt;()?</code></p>
</li>
<li>
<p><a href="https://docs.rs/quote/1.0/quote/trait.ToTokens.html">Printing</a><code>quote!( ... #the_token ... )</code></p>
</li>
<li>
<p>Construction from a <a href="https://docs.rs/proc-macro2/1.0/proc_macro2/struct.Span.html"><code>Span</code></a><code>let the_token = Token![...](sp)</code></p>
</li>
<li>
<p>Field access to its span — <code>let sp = the_token.span</code></p>
</li>
</ul>
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Abstract.html" title="struct syn::token::Abstract">Abstract</a></div><div class="desc docblock-short"><code>abstract</code></div></li><li><div class="item-name"><a class="struct" href="struct.Add.html" title="struct syn::token::Add">Add</a></div><div class="desc docblock-short"><code>+</code></div></li><li><div class="item-name"><a class="struct" href="struct.AddEq.html" title="struct syn::token::AddEq">AddEq</a></div><div class="desc docblock-short"><code>+=</code></div></li><li><div class="item-name"><a class="struct" href="struct.And.html" title="struct syn::token::And">And</a></div><div class="desc docblock-short"><code>&amp;</code></div></li><li><div class="item-name"><a class="struct" href="struct.AndAnd.html" title="struct syn::token::AndAnd">AndAnd</a></div><div class="desc docblock-short"><code>&amp;&amp;</code></div></li><li><div class="item-name"><a class="struct" href="struct.AndEq.html" title="struct syn::token::AndEq">AndEq</a></div><div class="desc docblock-short"><code>&amp;=</code></div></li><li><div class="item-name"><a class="struct" href="struct.As.html" title="struct syn::token::As">As</a></div><div class="desc docblock-short"><code>as</code></div></li><li><div class="item-name"><a class="struct" href="struct.Async.html" title="struct syn::token::Async">Async</a></div><div class="desc docblock-short"><code>async</code></div></li><li><div class="item-name"><a class="struct" href="struct.At.html" title="struct syn::token::At">At</a></div><div class="desc docblock-short"><code>@</code></div></li><li><div class="item-name"><a class="struct" href="struct.Auto.html" title="struct syn::token::Auto">Auto</a></div><div class="desc docblock-short"><code>auto</code></div></li><li><div class="item-name"><a class="struct" href="struct.Await.html" title="struct syn::token::Await">Await</a></div><div class="desc docblock-short"><code>await</code></div></li><li><div class="item-name"><a class="struct" href="struct.Bang.html" title="struct syn::token::Bang">Bang</a></div><div class="desc docblock-short"><code>!</code></div></li><li><div class="item-name"><a class="struct" href="struct.Become.html" title="struct syn::token::Become">Become</a></div><div class="desc docblock-short"><code>become</code></div></li><li><div class="item-name"><a class="struct" href="struct.Box.html" title="struct syn::token::Box">Box</a></div><div class="desc docblock-short"><code>box</code></div></li><li><div class="item-name"><a class="struct" href="struct.Brace.html" title="struct syn::token::Brace">Brace</a></div><div class="desc docblock-short"><code>{...}</code></div></li><li><div class="item-name"><a class="struct" href="struct.Bracket.html" title="struct syn::token::Bracket">Bracket</a></div><div class="desc docblock-short"><code>[...]</code></div></li><li><div class="item-name"><a class="struct" href="struct.Break.html" title="struct syn::token::Break">Break</a></div><div class="desc docblock-short"><code>break</code></div></li><li><div class="item-name"><a class="struct" href="struct.Caret.html" title="struct syn::token::Caret">Caret</a></div><div class="desc docblock-short"><code>^</code></div></li><li><div class="item-name"><a class="struct" href="struct.CaretEq.html" title="struct syn::token::CaretEq">CaretEq</a></div><div class="desc docblock-short"><code>^=</code></div></li><li><div class="item-name"><a class="struct" href="struct.Colon.html" title="struct syn::token::Colon">Colon</a></div><div class="desc docblock-short"><code>:</code></div></li><li><div class="item-name"><a class="struct" href="struct.Colon2.html" title="struct syn::token::Colon2">Colon2</a></div><div class="desc docblock-short"><code>::</code></div></li><li><div class="item-name"><a class="struct" href="struct.Comma.html" title="struct syn::token::Comma">Comma</a></div><div class="desc docblock-short"><code>,</code></div></li><li><div class="item-name"><a class="struct"