mcquery-rs/doc/syn/parse/struct.ParseBuffer.html

426 lines
69 KiB
HTML
Raw Normal View History

2021-01-08 20:01:01 +01:00
<!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="API documentation for the Rust `ParseBuffer` struct in crate `syn`."><meta name="keywords" content="rust, rustlang, rust-lang, ParseBuffer"><title>syn::parse::ParseBuffer - 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><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 struct"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../../syn/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Struct ParseBuffer</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#implementations">Methods</a><div class="sidebar-links"><a href="#method.call">call</a><a href="#method.cursor">cursor</a><a href="#method.error">error</a><a href="#method.fork">fork</a><a href="#method.is_empty">is_empty</a><a href="#method.lookahead1">lookahead1</a><a href="#method.parse">parse</a><a href="#method.parse_terminated">parse_terminated</a><a href="#method.peek">peek</a><a href="#method.peek2">peek2</a><a href="#method.peek3">peek3</a><a href="#method.span">span</a><a href="#method.step">step</a></div><a class="sidebar-title" href="#trait-implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Debug">Debug</a><a href="#impl-Display">Display</a><a href="#impl-Drop">Drop</a><a href="#impl-Speculative">Speculative</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-RefUnwindSafe">!RefUnwindSafe</a><a href="#impl-Send">!Send</a><a href="#impl-Sync">!Sync</a><a href="#impl-Unpin">Unpin</a><a href="#impl-UnwindSafe">!UnwindSafe</a></div><a class="sidebar-title" href="#blanket-implementations">Blanket Implementations</a><div class="sidebar-links"><a href="#impl-Any">Any</a><a href="#impl-Borrow%3CT%3E">Borrow&lt;T&gt;</a><a href="#impl-BorrowMut%3CT%3E">BorrowMut&lt;T&gt;</a><a href="#impl-From%3CT%3E">From&lt;T&gt;</a><a href="#impl-Into%3CU%3E">Into&lt;U&gt;</a><a href="#impl-ToString">ToString</a><a href="#impl-TryFrom%3CU%3E">TryFrom&lt;U&gt;</a><a href="#impl-TryInto%3CU%3E">TryInto&lt;U&gt;</a></div></div><p class="location"><a href="../index.html">syn</a>::<wbr><a href="index.html">parse</a></p><script>window.sidebarCurrent = {name: "ParseBuffer", ty: "struct", relpath: ""};</script><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" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><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><span class="help-button">?</span>
<a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/syn/parse.rs.html#249-265" title="goto source code">[src]</a></span><span class="in-band">Struct <a href="../index.html">syn</a>::<wbr><a href="index.html">parse</a>::<wbr><a class="struct" href="">ParseBuffer</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust struct">pub struct ParseBuffer&lt;'a&gt; { /* fields omitted */ }</pre></div><div class="docblock"><p>Cursor position within a buffered token stream.</p>
<p>This type is more commonly used through the type alias <a href="../../syn/parse/type.ParseStream.html" title="ParseStream"><code>ParseStream</code></a> which
is an alias for <code>&amp;ParseBuffer</code>.</p>
<p><code>ParseStream</code> is the input type for all parser functions in Syn. They have
the signature <code>fn(ParseStream) -&gt; Result&lt;T&gt;</code>.</p>
<h2 id="calling-a-parser-function" class="section-header"><a href="#calling-a-parser-function">Calling a parser function</a></h2>
<p>There is no public way to construct a <code>ParseBuffer</code>. Instead, if you are
looking to invoke a parser function that requires <code>ParseStream</code> as input,
you will need to go through one of the public parsing entry points.</p>
<ul>
<li>The <a href="../../syn/macro.parse_macro_input.html" title="parse_macro_input!"><code>parse_macro_input!</code></a> macro if parsing input of a procedural macro;</li>
<li>One of <a href="../../syn/parse/index.html#the-synparse-functions">the <code>syn::parse*</code> functions</a>; or</li>
<li>A method of the <a href="../../syn/parse/trait.Parser.html" title="Parser"><code>Parser</code></a> trait.</li>
</ul>
</div><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><h3 id="impl" class="impl"><code class="in-band">impl&lt;'a&gt; <a class="struct" href="../../syn/parse/struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a>&lt;'a&gt;</code><a href="#impl" class="anchor"></a><a class="srclink" href="../../src/syn/parse.rs.html#461-1060" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.parse" class="method"><code>pub fn <a href="#method.parse" class="fnname">parse</a>&lt;T:&nbsp;<a class="trait" href="../../syn/parse/trait.Parse.html" title="trait syn::parse::Parse">Parse</a>&gt;(&amp;self) -&gt; <a class="type" href="../../syn/parse/type.Result.html" title="type syn::parse::Result">Result</a>&lt;T&gt;</code><a class="srclink" href="../../src/syn/parse.rs.html#464-466" title="goto source code">[src]</a></h4><div class="docblock"><p>Parses a syntax tree node of type <code>T</code>, advancing the position of our
parse stream past it.</p>
</div><h4 id="method.call" class="method"><code>pub fn <a href="#method.call" class="fnname">call</a>&lt;T&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;function: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.fn.html">fn</a>(_: <a class="type" href="../../syn/parse/type.ParseStream.html" title="type syn::parse::ParseStream">ParseStream</a>&lt;'_&gt;) -&gt; <a class="type" href="../../syn/parse/type.Result.html" title="type syn::parse::Result">Result</a>&lt;T&gt;<br>) -&gt; <a class="type" href="../../syn/parse/type.Result.html" title="type syn::parse::Result">Result</a>&lt;T&gt;</code><a class="srclink" href="../../src/syn/parse.rs.html#504-506" title="goto source code">[src]</a></h4><div class="docblock"><p>Calls the given parser function to parse a syntax tree node of type <code>T</code>
from this stream.</p>
<h1 id="example" class="section-header"><a href="#example">Example</a></h1>
<p>The parser below invokes <a href="../../syn/struct.Attribute.html#method.parse_outer"><code>Attribute::parse_outer</code></a> to parse a vector of
zero or more outer attributes.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">syn</span>::{<span class="ident">Attribute</span>, <span class="ident">Ident</span>, <span class="prelude-ty">Result</span>, <span class="ident">Token</span>};
<span class="kw">use</span> <span class="ident">syn</span>::<span class="ident">parse</span>::{<span class="ident">Parse</span>, <span class="ident">ParseStream</span>};
<span class="comment">// Parses a unit struct with attributes.</span>
<span class="comment">//</span>
<span class="comment">// #[path = &quot;s.tmpl&quot;]</span>
<span class="comment">// struct S;</span>
<span class="kw">struct</span> <span class="ident">UnitStruct</span> {
<span class="ident">attrs</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">Attribute</span><span class="op">&gt;</span>,
<span class="ident">struct_token</span>: <span class="macro">Token</span><span class="macro">!</span>[<span class="kw">struct</span>],
<span class="ident">name</span>: <span class="ident">Ident</span>,
<span class="ident">semi_token</span>: <span class="macro">Token</span><span class="macro">!</span>[;],
}
<span class="kw">impl</span> <span class="ident">Parse</span> <span class="kw">for</span> <span class="ident">UnitStruct</span> {
<span class="kw">fn</span> <span class="ident">parse</span>(<span class="ident">input</span>: <span class="ident">ParseStream</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span><span class="op">&gt;</span> {
<span class="prelude-val">Ok</span>(<span class="ident">UnitStruct</span> {
<span class="ident">attrs</span>: <span class="ident">input</span>.<span class="ident">call</span>(<span class="ident">Attribute</span>::<span class="ident">parse_outer</span>)<span class="question-mark">?</span>,
<span class="ident">struct_token</span>: <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>,
<span class="ident">name</span>: <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>,
<span class="ident">semi_token</span>: <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>,
})
}
}</pre></div>
</div><h4 id="method.peek" class="method"><code>pub fn <a href="#method.peek" class="fnname">peek</a>&lt;T:&nbsp;<a class="trait" href="../../syn/parse/trait.Peek.html" title="trait syn::parse::Peek">Peek</a>&gt;(&amp;self, token: T) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class="srclink" href="../../src/syn/parse.rs.html#580-583" title="goto source code">[src]</a></h4><div class="docblock"><p>Looks at the next token in the parse stream to determine whether it
matches the requested type of token.</p>
<p>Does not advance the position of the parse stream.</p>
<h1 id="syntax" class="section-header"><a href="#syntax">Syntax</a></h1>
<p>Note that this method does not use turbofish syntax. Pass the peek type
inside of parentheses.</p>
<ul>
<li><code>input.peek(Token![struct])</code></li>
<li><code>input.peek(Token![==])</code></li>
<li><code>input.peek(Ident)</code><em>(does not accept keywords)</em></li>
<li><code>input.peek(Ident::peek_any)</code></li>
<li><code>input.peek(Lifetime)</code></li>
<li><code>input.peek(token::Brace)</code></li>
</ul>
<h1 id="example-1" class="section-header"><a href="#example-1">Example</a></h1>
<p>In this example we finish parsing the list of supertraits when the next
token in the input is either <code>where</code> or an opening curly brace.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">syn</span>::{<span class="ident">braced</span>, <span class="ident">token</span>, <span class="ident">Generics</span>, <span class="ident">Ident</span>, <span class="prelude-ty">Result</span>, <span class="ident">Token</span>, <span class="ident">TypeParamBound</span>};
<span class="kw">use</span> <span class="ident">syn</span>::<span class="ident">parse</span>::{<span class="ident">Parse</span>, <span class="ident">ParseStream</span>};
<span class="kw">use</span> <span class="ident">syn</span>::<span class="ident">punctuated</span>::<span class="ident">Punctuated</span>;
<span class="comment">// Parses a trait definition containing no associated items.</span>
<span class="comment">//</span>
<span class="comment">// trait Marker&lt;&#39;de, T&gt;: A + B&lt;&#39;de&gt; where Box&lt;T&gt;: Clone {}</span>
<span class="kw">struct</span> <span class="ident">MarkerTrait</span> {
<span class="ident">trait_token</span>: <span class="macro">Token</span><span class="macro">!</span>[<span class="kw">trait</span>],
<span class="ident">ident</span>: <span class="ident">Ident</span>,
<span class="ident">generics</span>: <span class="ident">Generics</span>,
<span class="ident">colon_token</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="macro">Token</span><span class="macro">!</span>[:]<span class="op">&gt;</span>,
<span class="ident">supertraits</span>: <span class="ident">Punctuated</span><span class="op">&lt;</span><span class="ident">TypeParamBound</span>, <span class="macro">Token</span><span class="macro">!</span>[<span class="op">+</span>]<span class="op">&gt;</span>,
<span class="ident">brace_token</span>: <span class="ident">token</span>::<span class="ident">Brace</span>,
}
<span class="kw">impl</span> <span class="ident">Parse</span> <span class="kw">for</span> <span class="ident">MarkerTrait</span> {
<span class="kw">fn</span> <span class="ident">parse</span>(<span class="ident">input</span>: <span class="ident">ParseStream</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="ident">trait_token</span>: <span class="macro">Token</span><span class="macro">!</span>[<span class="kw">trait</span>] <span class="op">=</span> <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>;
<span class="kw">let</span> <span class="ident">ident</span>: <span class="ident">Ident</span> <span class="op">=</span> <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">generics</span>: <span class="ident">Generics</span> <span class="op">=</span> <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>;
<span class="kw">let</span> <span class="ident">colon_token</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="macro">Token</span><span class="macro">!</span>[:]<span class="op">&gt;</span> <span class="op">=</span> <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">supertraits</span> <span class="op">=</span> <span class="ident">Punctuated</span>::<span class="ident">new</span>();
<span class="kw">if</span> <span class="ident">colon_token</span>.<span class="ident">is_some</span>() {
<span class="kw">loop</span> {
<span class="ident">supertraits</span>.<span class="ident">push_value</span>(<span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>);
<span class="kw">if</span> <span class="ident">input</span>.<span class="ident">peek</span>(<span class="macro">Token</span><span class="macro">!</span>[<span class="kw">where</span>]) <span class="op">|</span><span class="op">|</span> <span class="ident">input</span>.<span class="ident">peek</span>(<span class="ident">token</span>::<span class="ident">Brace</span>) {
<span class="kw">break</span>;
}
<span class="ident">supertraits</span>.<span class="ident">push_punct</span>(<span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>);
}
}
<span class="ident">generics</span>.<span class="ident">where_clause</span> <span class="op">=</span> <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>;
<span class="kw">let</span> <span class="ident">content</span>;
<span class="kw">let</span> <span class="ident">empty_brace_token</span> <span class="op">=</span> <span class="macro">braced</span><span class="macro">!</span>(<span class="ident">content</span> <span class="kw">in</span> <span class="ident">input</span>);
<span class="prelude-val">Ok</span>(<span class="ident">MarkerTrait</span> {
<span class="ident">trait_token</span>,
<span class="ident">ident</span>,
<span class="ident">generics</span>,
<span class="ident">colon_token</span>,
<span class="ident">supertraits</span>,
<span class="ident">brace_token</span>: <span class="ident">empty_brace_token</span>,
})
}
}</pre></div>
</div><h4 id="method.peek2" class="method"><code>pub fn <a href="#method.peek2" class="fnname">peek2</a>&lt;T:&nbsp;<a class="trait" href="../../syn/parse/trait.Peek.html" title="trait syn::parse::Peek">Peek</a>&gt;(&amp;self, token: T) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class="srclink" href="../../src/syn/parse.rs.html#619-631" title="goto source code">[src]</a></h4><div class="docblock"><p>Looks at the second-next token in the parse stream.</p>
<p>This is commonly useful as a way to implement contextual keywords.</p>
<h1 id="example-2" class="section-header"><a href="#example-2">Example</a></h1>
<p>This example needs to use <code>peek2</code> because the symbol <code>union</code> is not a
keyword in Rust. We can't use just <code>peek</code> and decide to parse a union if
the very next token is <code>union</code>, because someone is free to write a <code>mod union</code> and a macro invocation that looks like <code>union::some_macro! { ... }</code>. In other words <code>union</code> is a contextual keyword.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">syn</span>::{<span class="ident">Ident</span>, <span class="ident">ItemUnion</span>, <span class="ident">Macro</span>, <span class="prelude-ty">Result</span>, <span class="ident">Token</span>};
<span class="kw">use</span> <span class="ident">syn</span>::<span class="ident">parse</span>::{<span class="ident">Parse</span>, <span class="ident">ParseStream</span>};
<span class="comment">// Parses either a union or a macro invocation.</span>
<span class="kw">enum</span> <span class="ident">UnionOrMacro</span> {
<span class="comment">// union MaybeUninit&lt;T&gt; { uninit: (), value: T }</span>
<span class="ident">Union</span>(<span class="ident">ItemUnion</span>),
<span class="comment">// lazy_static! { ... }</span>
<span class="ident">Macro</span>(<span class="ident">Macro</span>),
}
<span class="kw">impl</span> <span class="ident">Parse</span> <span class="kw">for</span> <span class="ident">UnionOrMacro</span> {
<span class="kw">fn</span> <span class="ident">parse</span>(<span class="ident">input</span>: <span class="ident">ParseStream</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span><span class="op">&gt;</span> {
<span class="kw">if</span> <span class="ident">input</span>.<span class="ident">peek</span>(<span class="macro">Token</span><span class="macro">!</span>[<span class="ident">union</span>]) <span class="op">&amp;&amp;</span> <span class="ident">input</span>.<span class="ident">peek2</span>(<span class="ident">Ident</span>) {
<span class="ident">input</span>.<span class="ident">parse</span>().<span class="ident">map</span>(<span class="ident">UnionOrMacro</span>::<span class="ident">Union</span>)
} <span class="kw">else</span> {
<span class="ident">input</span>.<span class="ident">parse</span>().<span class="ident">map</span>(<span class="ident">UnionOrMacro</span>::<span class="ident">Macro</span>)
}
}
}</pre></div>
</div><h4 id="method.peek3" class="method"><code>pub fn <a href="#method.peek3" class="fnname">peek3</a>&lt;T:&nbsp;<a class="trait" href="../../syn/parse/trait.Peek.html" title="trait syn::parse::Peek">Peek</a>&gt;(&amp;self, token: T) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class="srclink" href="../../src/syn/parse.rs.html#634-650" title="goto source code">[src]</a></h4><div class="docblock"><p>Looks at the third-next token in the parse stream.</p>
</div><h4 id="method.parse_terminated" class="method"><code>pub fn <a href="#method.parse_terminated" class="fnname">parse_terminated</a>&lt;T, P:&nbsp;<a class="trait" href="../../syn/parse/trait.Parse.html" title="trait syn::parse::Parse">Parse</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;parser: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.fn.html">fn</a>(_: <a class="type" href="../../syn/parse/type.ParseStream.html" title="type syn::parse::ParseStream">ParseStream</a>&lt;'_&gt;) -&gt; <a class="type" href="../../syn/parse/type.Result.html" title="type syn::parse::Result">Result</a>&lt;T&gt;<br>) -&gt; <a class="type" href="../../syn/parse/type.Result.html" title="type syn::parse::Result">Result</a>&lt;<a class="struct" href="../../syn/punctuated/struct.Punctuated.html" title="struct syn::punctuated::Punctuated">Punctuated</a>&lt;T, P&gt;&gt;</code><a class="srclink" href="../../src/syn/parse.rs.html#696-701" title="goto source code">[src]</a></h4><div class="docblock"><p>Parses zero or more occurrences of <code>T</code> separated by punctuation of type
<code>P</code>, with optional trailing punctuation.</p>
<p>Parsing continues until the end of this parse stream. The entire content
of this parse stream must consist of <code>T</code> and <code>P</code>.</p>
<h1 id="example-3" class="section-header"><a href="#example-3">Example</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">syn</span>::{<span class="ident">parenthesized</span>, <span class="ident">token</span>, <span class="ident">Ident</span>, <span class="prelude-ty">Result</span>, <span class="ident">Token</span>, <span class="ident">Type</span>};
<span class="kw">use</span> <span class="ident">syn</span>::<span class="ident">parse</span>::{<span class="ident">Parse</span>, <span class="ident">ParseStream</span>};
<span class="kw">use</span> <span class="ident">syn</span>::<span class="ident">punctuated</span>::<span class="ident">Punctuated</span>;
<span class="comment">// Parse a simplified tuple struct syntax like:</span>
<span class="comment">//</span>
<span class="comment">// struct S(A, B);</span>
<span class="kw">struct</span> <span class="ident">TupleStruct</span> {
<span class="ident">struct_token</span>: <span class="macro">Token</span><span class="macro">!</span>[<span class="kw">struct</span>],
<span class="ident">ident</span>: <span class="ident">Ident</span>,
<span class="ident">paren_token</span>: <span class="ident">token</span>::<span class="ident">Paren</span>,
<span class="ident">fields</span>: <span class="ident">Punctuated</span><span class="op">&lt;</span><span class="ident">Type</span>, <span class="macro">Token</span><span class="macro">!</span>[,]<span class="op">&gt;</span>,
<span class="ident">semi_token</span>: <span class="macro">Token</span><span class="macro">!</span>[;],
}
<span class="kw">impl</span> <span class="ident">Parse</span> <span class="kw">for</span> <span class="ident">TupleStruct</span> {
<span class="kw">fn</span> <span class="ident">parse</span>(<span class="ident">input</span>: <span class="ident">ParseStream</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="ident">content</span>;
<span class="prelude-val">Ok</span>(<span class="ident">TupleStruct</span> {
<span class="ident">struct_token</span>: <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>,
<span class="ident">ident</span>: <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>,
<span class="ident">paren_token</span>: <span class="macro">parenthesized</span><span class="macro">!</span>(<span class="ident">content</span> <span class="kw">in</span> <span class="ident">input</span>),
<span class="ident">fields</span>: <span class="ident">content</span>.<span class="ident">parse_terminated</span>(<span class="ident">Type</span>::<span class="ident">parse</span>)<span class="question-mark">?</span>,
<span class="ident">semi_token</span>: <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>,
})
}
}</pre></div>
</div><h4 id="method.is_empty" class="method"><code>pub fn <a href="#method.is_empty" class="fnname">is_empty</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class="srclink" href="../../src/syn/parse.rs.html#740-742" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns whether there are tokens remaining in this stream.</p>
<p>This method returns true at the end of the content of a set of
delimiters, as well as at the very end of the complete macro input.</p>
<h1 id="example-4" class="section-header"><a href="#example-4">Example</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">syn</span>::{<span class="ident">braced</span>, <span class="ident">token</span>, <span class="ident">Ident</span>, <span class="ident">Item</span>, <span class="prelude-ty">Result</span>, <span class="ident">Token</span>};
<span class="kw">use</span> <span class="ident">syn</span>::<span class="ident">parse</span>::{<span class="ident">Parse</span>, <span class="ident">ParseStream</span>};
<span class="comment">// Parses a Rust `mod m { ... }` containing zero or more items.</span>
<span class="kw">struct</span> <span class="ident">Mod</span> {
<span class="ident">mod_token</span>: <span class="macro">Token</span><span class="macro">!</span>[<span class="kw">mod</span>],
<span class="ident">name</span>: <span class="ident">Ident</span>,
<span class="ident">brace_token</span>: <span class="ident">token</span>::<span class="ident">Brace</span>,
<span class="ident">items</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">Item</span><span class="op">&gt;</span>,
}
<span class="kw">impl</span> <span class="ident">Parse</span> <span class="kw">for</span> <span class="ident">Mod</span> {
<span class="kw">fn</span> <span class="ident">parse</span>(<span class="ident">input</span>: <span class="ident">ParseStream</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="ident">content</span>;
<span class="prelude-val">Ok</span>(<span class="ident">Mod</span> {
<span class="ident">mod_token</span>: <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>,
<span class="ident">name</span>: <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>,
<span class="ident">brace_token</span>: <span class="macro">braced</span><span class="macro">!</span>(<span class="ident">content</span> <span class="kw">in</span> <span class="ident">input</span>),
<span class="ident">items</span>: {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">items</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">new</span>();
<span class="kw">while</span> <span class="op">!</span><span class="ident">content</span>.<span class="ident">is_empty</span>() {
<span class="ident">items</span>.<span class="ident">push</span>(<span class="ident">content</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>);
}
<span class="ident">items</span>
},
})
}
}</pre></div>
</div><h4 id="method.lookahead1" class="method"><code>pub fn <a href="#method.lookahead1" class="fnname">lookahead1</a>(&amp;self) -&gt; <a class="struct" href="../../syn/parse/struct.Lookahead1.html" title="struct syn::parse::Lookahead1">Lookahead1</a>&lt;'a&gt;</code><a class="srclink" href="../../src/syn/parse.rs.html#785-787" title="goto source code">[src]</a></h4><div class="docblock"><p>Constructs a helper for peeking at the next token in this stream and
building an error message if it is not one of a set of expected tokens.</p>
<h1 id="example-5" class="section-header"><a href="#example-5">Example</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">syn</span>::{<span class="ident">ConstParam</span>, <span class="ident">Ident</span>, <span class="ident">Lifetime</span>, <span class="ident">LifetimeDef</span>, <span class="prelude-ty">Result</span>, <span class="ident">Token</span>, <span class="ident">TypeParam</span>};
<span class="kw">use</span> <span class="ident">syn</span>::<span class="ident">parse</span>::{<span class="ident">Parse</span>, <span class="ident">ParseStream</span>};
<span class="comment">// A generic parameter, a single one of the comma-separated elements inside</span>
<span class="comment">// angle brackets in:</span>
<span class="comment">//</span>
<span class="comment">// fn f&lt;T: Clone, &#39;a, &#39;b: &#39;a, const N: usize&gt;() { ... }</span>
<span class="comment">//</span>
<span class="comment">// On invalid input, lookahead gives us a reasonable error message.</span>
<span class="comment">//</span>
<span class="comment">// error: expected one of: identifier, lifetime, `const`</span>
<span class="comment">// |</span>
<span class="comment">// 5 | fn f&lt;!Sized&gt;() {}</span>
<span class="comment">// | ^</span>
<span class="kw">enum</span> <span class="ident">GenericParam</span> {
<span class="ident">Type</span>(<span class="ident">TypeParam</span>),
<span class="ident">Lifetime</span>(<span class="ident">LifetimeDef</span>),
<span class="ident">Const</span>(<span class="ident">ConstParam</span>),
}
<span class="kw">impl</span> <span class="ident">Parse</span> <span class="kw">for</span> <span class="ident">GenericParam</span> {
<span class="kw">fn</span> <span class="ident">parse</span>(<span class="ident">input</span>: <span class="ident">ParseStream</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="ident">lookahead</span> <span class="op">=</span> <span class="ident">input</span>.<span class="ident">lookahead1</span>();
<span class="kw">if</span> <span class="ident">lookahead</span>.<span class="ident">peek</span>(<span class="ident">Ident</span>) {
<span class="ident">input</span>.<span class="ident">parse</span>().<span class="ident">map</span>(<span class="ident">GenericParam</span>::<span class="ident">Type</span>)
} <span class="kw">else</span> <span class="kw">if</span> <span class="ident">lookahead</span>.<span class="ident">peek</span>(<span class="ident">Lifetime</span>) {
<span class="ident">input</span>.<span class="ident">parse</span>().<span class="ident">map</span>(<span class="ident">GenericParam</span>::<span class="ident">Lifetime</span>)
} <span class="kw">else</span> <span class="kw">if</span> <span class="ident">lookahead</span>.<span class="ident">peek</span>(<span class="macro">Token</span><span class="macro">!</span>[<span class="kw">const</span>]) {
<span class="ident">input</span>.<span class="ident">parse</span>().<span class="ident">map</span>(<span class="ident">GenericParam</span>::<span class="ident">Const</span>)
} <span class="kw">else</span> {
<span class="prelude-val">Err</span>(<span class="ident">lookahead</span>.<span class="ident">error</span>())
}
}
}</pre></div>
</div><h4 id="method.fork" class="method"><code>pub fn <a href="#method.fork" class="fnname">fork</a>(&amp;self) -&gt; Self</code><a class="srclink" href="../../src/syn/parse.rs.html#915-924" title="goto source code">[src]</a></h4><div class="docblock"><p>Forks a parse stream so that parsing tokens out of either the original
or the fork does not advance the position of the other.</p>
<h1 id="performance" class="section-header"><a href="#performance">Performance</a></h1>
<p>Forking a parse stream is a cheap fixed amount of work and does not
involve copying token buffers. Where you might hit performance problems
is if your macro ends up parsing a large amount of content more than
once.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="comment">// Do not do this.</span>
<span class="kw">if</span> <span class="ident">input</span>.<span class="ident">fork</span>().<span class="ident">parse</span>::<span class="op">&lt;</span><span class="ident">Expr</span><span class="op">&gt;</span>().<span class="ident">is_ok</span>() {
<span class="kw">return</span> <span class="ident">input</span>.<span class="ident">parse</span>::<span class="op">&lt;</span><span class="ident">Expr</span><span class="op">&gt;</span>();
}</pre></div>
<p>As a rule, avoid parsing an unbounded amount of tokens out of a forked
parse stream. Only use a fork when the amount of work performed against
the fork is small and bounded.</p>
<p>When complex speculative parsing against the forked stream is
unavoidable, use <a href="../../syn/parse/discouraged/trait.Speculative.html"><code>parse::discouraged::Speculative</code></a> to advance the
original stream once the fork's parse is determined to have been
successful.</p>
<p>For a lower level way to perform speculative parsing at the token level,
consider using <a href="../../syn/parse/struct.ParseBuffer.html#method.step"><code>ParseStream::step</code></a> instead.</p>
<h1 id="example-6" class="section-header"><a href="#example-6">Example</a></h1>
<p>The parse implementation shown here parses possibly restricted <code>pub</code>
visibilities.</p>
<ul>
<li><code>pub</code></li>
<li><code>pub(crate)</code></li>
<li><code>pub(self)</code></li>
<li><code>pub(super)</code></li>
<li><code>pub(in some::path)</code></li>
</ul>
<p>To handle the case of visibilities inside of tuple structs, the parser
needs to distinguish parentheses that specify visibility restrictions
from parentheses that form part of a tuple type.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">struct</span> <span class="ident">S</span>(<span class="kw">pub</span>(<span class="kw">crate</span>) <span class="ident">A</span>, <span class="kw">pub</span> (<span class="ident">B</span>, <span class="ident">C</span>));</pre></div>
<p>In this example input the first tuple struct element of <code>S</code> has
<code>pub(crate)</code> visibility while the second tuple struct element has <code>pub</code>
visibility; the parentheses around <code>(B, C)</code> are part of the type rather
than part of a visibility restriction.</p>
<p>The parser uses a forked parse stream to check the first token inside of
parentheses after the <code>pub</code> keyword. This is a small bounded amount of
work performed against the forked parse stream.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">syn</span>::{<span class="ident">parenthesized</span>, <span class="ident">token</span>, <span class="ident">Ident</span>, <span class="ident">Path</span>, <span class="prelude-ty">Result</span>, <span class="ident">Token</span>};
<span class="kw">use</span> <span class="ident">syn</span>::<span class="ident">ext</span>::<span class="ident">IdentExt</span>;
<span class="kw">use</span> <span class="ident">syn</span>::<span class="ident">parse</span>::{<span class="ident">Parse</span>, <span class="ident">ParseStream</span>};
<span class="kw">struct</span> <span class="ident">PubVisibility</span> {
<span class="ident">pub_token</span>: <span class="macro">Token</span><span class="macro">!</span>[<span class="kw">pub</span>],
<span class="ident">restricted</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">Restricted</span><span class="op">&gt;</span>,
}
<span class="kw">struct</span> <span class="ident">Restricted</span> {
<span class="ident">paren_token</span>: <span class="ident">token</span>::<span class="ident">Paren</span>,
<span class="ident">in_token</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="macro">Token</span><span class="macro">!</span>[<span class="kw">in</span>]<span class="op">&gt;</span>,
<span class="ident">path</span>: <span class="ident">Path</span>,
}
<span class="kw">impl</span> <span class="ident">Parse</span> <span class="kw">for</span> <span class="ident">PubVisibility</span> {
<span class="kw">fn</span> <span class="ident">parse</span>(<span class="ident">input</span>: <span class="ident">ParseStream</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="ident">pub_token</span>: <span class="macro">Token</span><span class="macro">!</span>[<span class="kw">pub</span>] <span class="op">=</span> <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>;
<span class="kw">if</span> <span class="ident">input</span>.<span class="ident">peek</span>(<span class="ident">token</span>::<span class="ident">Paren</span>) {
<span class="kw">let</span> <span class="ident">ahead</span> <span class="op">=</span> <span class="ident">input</span>.<span class="ident">fork</span>();
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">content</span>;
<span class="macro">parenthesized</span><span class="macro">!</span>(<span class="ident">content</span> <span class="kw">in</span> <span class="ident">ahead</span>);
<span class="kw">if</span> <span class="ident">content</span>.<span class="ident">peek</span>(<span class="macro">Token</span><span class="macro">!</span>[<span class="kw">crate</span>])
<span class="op">|</span><span class="op">|</span> <span class="ident">content</span>.<span class="ident">peek</span>(<span class="macro">Token</span><span class="macro">!</span>[<span class="self">self</span>])
<span class="op">|</span><span class="op">|</span> <span class="ident">content</span>.<span class="ident">peek</span>(<span class="macro">Token</span><span class="macro">!</span>[<span class="kw">super</span>])
{
<span class="kw">return</span> <span class="prelude-val">Ok</span>(<span class="ident">PubVisibility</span> {
<span class="ident">pub_token</span>,
<span class="ident">restricted</span>: <span class="prelude-val">Some</span>(<span class="ident">Restricted</span> {
<span class="ident">paren_token</span>: <span class="macro">parenthesized</span><span class="macro">!</span>(<span class="ident">content</span> <span class="kw">in</span> <span class="ident">input</span>),
<span class="ident">in_token</span>: <span class="prelude-val">None</span>,
<span class="ident">path</span>: <span class="ident">Path</span>::<span class="ident">from</span>(<span class="ident">content</span>.<span class="ident">call</span>(<span class="ident">Ident</span>::<span class="ident">parse_any</span>)<span class="question-mark">?</span>),
}),
});
} <span class="kw">else</span> <span class="kw">if</span> <span class="ident">content</span>.<span class="ident">peek</span>(<span class="macro">Token</span><span class="macro">!</span>[<span class="kw">in</span>]) {
<span class="kw">return</span> <span class="prelude-val">Ok</span>(<span class="ident">PubVisibility</span> {
<span class="ident">pub_token</span>,
<span class="ident">restricted</span>: <span class="prelude-val">Some</span>(<span class="ident">Restricted</span> {
<span class="ident">paren_token</span>: <span class="macro">parenthesized</span><span class="macro">!</span>(<span class="ident">content</span> <span class="kw">in</span> <span class="ident">input</span>),
<span class="ident">in_token</span>: <span class="prelude-val">Some</span>(<span class="ident">content</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>),
<span class="ident">path</span>: <span class="ident">content</span>.<span class="ident">call</span>(<span class="ident">Path</span>::<span class="ident">parse_mod_style</span>)<span class="question-mark">?</span>,
}),
});
}
}
<span class="prelude-val">Ok</span>(<span class="ident">PubVisibility</span> {
<span class="ident">pub_token</span>,
<span class="ident">restricted</span>: <span class="prelude-val">None</span>,
})
}
}</pre></div>
</div><h4 id="method.error" class="method"><code>pub fn <a href="#method.error" class="fnname">error</a>&lt;T:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>&gt;(&amp;self, message: T) -&gt; <a class="struct" href="../../syn/struct.Error.html" title="struct syn::Error">Error</a></code><a class="srclink" href="../../src/syn/parse.rs.html#954-956" title="goto source code">[src]</a></h4><div class="docblock"><p>Triggers an error at the current position of the parse stream.</p>
<h1 id="example-7" class="section-header"><a href="#example-7">Example</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">syn</span>::{<span class="ident">Expr</span>, <span class="prelude-ty">Result</span>, <span class="ident">Token</span>};
<span class="kw">use</span> <span class="ident">syn</span>::<span class="ident">parse</span>::{<span class="ident">Parse</span>, <span class="ident">ParseStream</span>};
<span class="comment">// Some kind of loop: `while` or `for` or `loop`.</span>
<span class="kw">struct</span> <span class="ident">Loop</span> {
<span class="ident">expr</span>: <span class="ident">Expr</span>,
}
<span class="kw">impl</span> <span class="ident">Parse</span> <span class="kw">for</span> <span class="ident">Loop</span> {
<span class="kw">fn</span> <span class="ident">parse</span>(<span class="ident">input</span>: <span class="ident">ParseStream</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span><span class="op">&gt;</span> {
<span class="kw">if</span> <span class="ident">input</span>.<span class="ident">peek</span>(<span class="macro">Token</span><span class="macro">!</span>[<span class="kw">while</span>])
<span class="op">|</span><span class="op">|</span> <span class="ident">input</span>.<span class="ident">peek</span>(<span class="macro">Token</span><span class="macro">!</span>[<span class="kw">for</span>])
<span class="op">|</span><span class="op">|</span> <span class="ident">input</span>.<span class="ident">peek</span>(<span class="macro">Token</span><span class="macro">!</span>[<span class="kw">loop</span>])
{
<span class="prelude-val">Ok</span>(<span class="ident">Loop</span> {
<span class="ident">expr</span>: <span class="ident">input</span>.<span class="ident">parse</span>()<span class="question-mark">?</span>,
})
} <span class="kw">else</span> {
<span class="prelude-val">Err</span>(<span class="ident">input</span>.<span class="ident">error</span>(<span class="string">&quot;expected some kind of loop&quot;</span>))
}
}
}</pre></div>
</div><h4 id="method.step" class="method"><code>pub fn <a href="#method.step" class="fnname">step</a>&lt;F, R&gt;(&amp;self, function: F) -&gt; <a class="type" href="../../syn/parse/type.Result.html" title="type syn::parse::Result">Result</a>&lt;R&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: for&lt;'c&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="struct" href="../../syn/parse/struct.StepCursor.html" title="struct syn::parse::StepCursor">StepCursor</a>&lt;'c, 'a&gt;) -&gt; <a class="type" href="../../syn/parse/type.Result.html" title="type syn::parse::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a>R, <a class="struct" href="../../syn/buffer/struct.Cursor.html" title="struct syn::buffer::Cursor">Cursor</a>&lt;'c&gt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>&gt;,&nbsp;</span></code><a class="srclink" href="../../src/syn/parse.rs.html#1003-1031" title="goto source code">[src]</a></h4><div class="docblock"><p>Speculatively parses tokens from this parse stream, advancing the
position of this stream only if parsing succeeds.</p>
<p>This is a powerful low-level API used for defining the <code>Parse</code> impls of
the basic built-in token types. It is not something that will be used
widely outside of the Syn codebase.</p>
<h1 id="example-8" class="section-header"><a href="#example-8">Example</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">proc_macro2</span>::<span class="ident">TokenTree</span>;
<span class="kw">use</span> <span class="ident">syn</span>::<span class="prelude-ty">Result</span>;
<span class="kw">use</span> <span class="ident">syn</span>::<span class="ident">parse</span>::<span class="ident">ParseStream</span>;
<span class="comment">// This function advances the stream past the next occurrence of `@`. If</span>
<span class="comment">// no `@` is present in the stream, the stream position is unchanged and</span>
<span class="comment">// an error is returned.</span>
<span class="kw">fn</span> <span class="ident">skip_past_next_at</span>(<span class="ident">input</span>: <span class="ident">ParseStream</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span>()<span class="op">&gt;</span> {
<span class="ident">input</span>.<span class="ident">step</span>(<span class="op">|</span><span class="ident">cursor</span><span class="op">|</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rest</span> <span class="op">=</span> <span class="kw-2">*</span><span class="ident">cursor</span>;
<span class="kw">while</span> <span class="kw">let</span> <span class="prelude-val">Some</span>((<span class="ident">tt</span>, <span class="ident">next</span>)) <span class="op">=</span> <span class="ident">rest</span>.<span class="ident">token_tree</span>() {
<span class="kw">match</span> <span class="kw-2">&amp;</span><span class="ident">tt</span> {
<span class="ident">TokenTree</span>::<span class="ident">Punct</span>(<span class="ident">punct</span>) <span class="kw">if</span> <span class="ident">punct</span>.<span class="ident">as_char</span>() <span class="op">=</span><span class="op">=</span> <span class="string">&#39;@&#39;</span> <span class="op">=</span><span class="op">&gt;</span> {
<span class="kw">return</span> <span class="prelude-val">Ok</span>(((), <span class="ident">next</span>));
}
<span class="kw">_</span> <span class="op">=</span><span class="op">&gt;</span> <span class="ident">rest</span> <span class="op">=</span> <span class="ident">next</span>,
}
}
<span class="prelude-val">Err</span>(<span class="ident">cursor</span>.<span class="ident">error</span>(<span class="string">&quot;no `@` was found after this point&quot;</span>))
})
}</pre></div>
</div><h4 id="method.span" class="method"><code>pub fn <a href="#method.span" class="fnname">span</a>(&amp;self) -&gt; <a class="struct" href="../../proc_macro2/struct.Span.html" title="struct proc_macro2::Span">Span</a></code><a class="srclink" href="../../src/syn/parse.rs.html#1036-1043" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns the <code>Span</code> of the next token in the parse stream, or
<code>Span::call_site()</code> if this parse stream has completely exhausted its
input <code>TokenStream</code>.</p>
</div><h4 id="method.cursor" class="method"><code>pub fn <a href="#method.cursor" class="fnname">cursor</a>(&amp;self) -&gt; <a class="struct" href="../../syn/buffer/struct.Cursor.html" title="struct syn::buffer::Cursor">Cursor</a>&lt;'a&gt;</code><a class="srclink" href="../../src/syn/parse.rs.html#1050-1052" title="goto source code">[src]</a></h4><div class="docblock"><p>Provides low-level access to the token representation underlying this
parse stream.</p>
<p>Cursors are immutable so no operations you perform against the cursor
will affect the state of this parse stream.</p>
</div></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><h3 id="impl-Debug" class="impl"><code class="in-band">impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../../syn/parse/struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a>&lt;'a&gt;</code><a href="#impl-Debug" class="anchor"></a><a class="srclink" href="../../src/syn/parse.rs.html#284-288" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.fmt" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code><a class="srclink" href="../../src/syn/parse.rs.html#285-287" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></div><h3 id="impl-Display" class="impl"><code class="in-band">impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> for <a class="struct" href="../../syn/parse/struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a>&lt;'a&gt;</code><a href="#impl-Display" class="anchor"></a><a class="srclink" href="../../src/syn/parse.rs.html#278-282" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.fmt-1" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#tymethod.fmt" class="fnname">fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code><a class="srclink" href="../../src/syn/parse.rs.html#279-281" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#tymethod.fmt">Read more</a></p>
</div></div><h3 id="impl-Drop" class="impl"><code class="in-band">impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html" title="trait core::ops::drop::Drop">Drop</a> for <a class="struct" href="../../syn/parse/struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a>&lt;'a&gt;</code><a href="#impl-Drop" class="anchor"></a><a class="srclink" href="../../src/syn/parse.rs.html#267-276" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.drop" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html#tymethod.drop" class="fnname">drop</a>(&amp;mut self)</code><a class="srclink" href="../../src/syn/parse.rs.html#268-275" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Executes the destructor for this type. <a href="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html#tymethod.drop">Read more</a></p>
</div></div><h3 id="impl-Speculative" class="impl"><code class="in-band">impl&lt;'a&gt; <a class="trait" href="../../syn/parse/discouraged/trait.Speculative.html" title="trait syn::parse::discouraged::Speculative">Speculative</a> for <a class="struct" href="../../syn/parse/struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a>&lt;'a&gt;</code><a href="#impl-Speculative" class="anchor"></a><a class="srclink" href="../../src/syn/discouraged.rs.html#160-194" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.advance_to" class="method hidden"><code>fn <a href="../../syn/parse/discouraged/trait.Speculative.html#tymethod.advance_to" class="fnname">advance_to</a>(&amp;self, fork: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>Self)</code><a class="srclink" href="../../src/syn/discouraged.rs.html#161-193" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Advance this parse stream to the position of a forked parse stream. <a href="../../syn/parse/discouraged/trait.Speculative.html#tymethod.advance_to">Read more</a></p>
</div></div></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><h3 id="impl-RefUnwindSafe" class="impl"><code class="in-band">impl&lt;'a&gt; !<a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.RefUnwindSafe.html" title="trait std::panic::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="../../syn/parse/struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a>&lt;'a&gt;</code><a href="#impl-RefUnwindSafe" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Send" class="impl"><code class="in-band">impl&lt;'a&gt; !<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="../../syn/parse/struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a>&lt;'a&gt;</code><a href="#impl-Send" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Sync" class="impl"><code class="in-band">impl&lt;'a&gt; !<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="../../syn/parse/struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a>&lt;'a&gt;</code><a href="#impl-Sync" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Unpin" class="impl"><code class="in-band">impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="../../syn/parse/struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a>&lt;'a&gt;</code><a href="#impl-Unpin" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-UnwindSafe" class="impl"><code class="in-band">impl&lt;'a&gt; !<a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a> for <a class="struct" href="../../syn/parse/struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a>&lt;'a&gt;</code><a href="#impl-UnwindSafe" class="anchor"></a></h3><div class="impl-items"></div></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><h3 id="impl-Any" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href="#impl-Any" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#108-112" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.type_id" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#109-111" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
</div></div><h3 id="impl-Borrow%3CT%3E" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href="#impl-Borrow%3CT%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#210-214" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.borrow" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#211-213" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
</div></div><h3 id="impl-BorrowMut%3CT%3E" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a>&lt;T&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href="#impl-BorrowMut%3CT%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#217-221" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.borrow_mut" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#218-220" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
</div></div><h3 id="impl-From%3CT%3E" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for T</code><a href="#impl-From%3CT%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#552-556" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.from" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: T) -&gt; T</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#553-555" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id="impl-Into%3CU%3E" class="impl"><code class="in-band">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;U&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt;,&nbsp;</span></code><a href="#impl-Into%3CU%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#541-548" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.into" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html#tymethod.into" class="fnname">into</a>(self) -&gt; U</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#545-547" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id="impl-ToString" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/string/trait.ToString.html" title="trait alloc::string::ToString">ToString</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href="#impl-ToString" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/string.rs.html#2194-2207" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.to_string" class="method hidden"><code>pub default fn <a href="https://doc.rust-lang.org/nightly/alloc/string/trait.ToString.html#tymethod.to_string" class="fnname">to_string</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/string.rs.html#2200-2206" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Converts the given value to a <code>String</code>. <a href="https://doc.rust-lang.org/nightly/alloc/string/trait.ToString.html#tymethod.to_string">Read more</a></p>
</div></div><h3 id="impl-TryFrom%3CU%3E" class="impl"><code class="in-band">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;T&gt;,&nbsp;</span></code><a href="#impl-TryFrom%3CU%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#589-598" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Error" class="type"><code>type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" class="type">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></code></h4><div class='docblock'><p>The type returned in the event of a conversion error.</p>
</div><h4 id="method.try_from" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from" class="fnname">try_from</a>(value: U) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T, &lt;T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt;&gt;::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#595-597" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id="impl-TryInto%3CU%3E" class="impl"><code class="in-band">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a>&lt;U&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;,&nbsp;</span></code><a href="#impl-TryInto%3CU%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#575-584" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Error-1" class="type"><code>type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error" class="type">Error</a> = &lt;U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></code></h4><div class='docblock'><p>The type returned in the event of a conversion error.</p>
</div><h4 id="method.try_into" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into" class="fnname">try_into</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;U, &lt;U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#581-583" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div></div></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../../";window.currentCrate = "syn";</script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>