mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-12-26 11:59:33 +01:00
505 lines
No EOL
65 KiB
HTML
505 lines
No EOL
65 KiB
HTML
<!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="Cursor position within a buffered token stream."><title>ParseBuffer in syn::parse - 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-492a78a4a87dcc01.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.82.0 (f6e511eec 2024-10-15)" data-channel="1.82.0" data-search-js="search-a99f1315e7cc5121.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-921df33f47b8780c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-3b12f09e550e0385.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 struct"><!--[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">2.0.85</span></h2></div><h2 class="location"><a href="#">Parse<wbr>Buffer</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.call">call</a></li><li><a href="#method.cursor">cursor</a></li><li><a href="#method.error">error</a></li><li><a href="#method.fork">fork</a></li><li><a href="#method.is_empty">is_empty</a></li><li><a href="#method.lookahead1">lookahead1</a></li><li><a href="#method.parse">parse</a></li><li><a href="#method.parse_terminated">parse_terminated</a></li><li><a href="#method.peek">peek</a></li><li><a href="#method.peek2">peek2</a></li><li><a href="#method.peek3">peek3</a></li><li><a href="#method.span">span</a></li><li><a href="#method.step">step</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-AnyDelimiter-for-ParseBuffer%3C'a%3E">AnyDelimiter</a></li><li><a href="#impl-Debug-for-ParseBuffer%3C'a%3E">Debug</a></li><li><a href="#impl-Display-for-ParseBuffer%3C'a%3E">Display</a></li><li><a href="#impl-Drop-for-ParseBuffer%3C'a%3E">Drop</a></li><li><a href="#impl-RefUnwindSafe-for-ParseBuffer%3C'a%3E">RefUnwindSafe</a></li><li><a href="#impl-Speculative-for-ParseBuffer%3C'a%3E">Speculative</a></li><li><a href="#impl-UnwindSafe-for-ParseBuffer%3C'a%3E">UnwindSafe</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Freeze-for-ParseBuffer%3C'a%3E">!Freeze</a></li><li><a href="#impl-Send-for-ParseBuffer%3C'a%3E">!Send</a></li><li><a href="#impl-Sync-for-ParseBuffer%3C'a%3E">!Sync</a></li><li><a href="#impl-Unpin-for-ParseBuffer%3C'a%3E">Unpin</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-T">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-T">Into<U></a></li><li><a href="#impl-ToString-for-T">ToString</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-T">TryInto<U></a></li></ul></section><h2><a href="index.html">In syn::<wbr>parse</a></h2></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Struct <a href="../index.html">syn</a>::<wbr><a href="index.html">parse</a>::<wbr><a class="struct" href="#">ParseBuffer</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><a class="src" href="../../src/syn/parse.rs.html#246-262">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub struct ParseBuffer<'a> { <span class="comment">/* private fields */</span> }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><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="type.ParseStream.html" title="type syn::parse::ParseStream"><code>ParseStream</code></a> which
|
||
is an alias for <code>&ParseBuffer</code>.</p>
|
||
<p><code>ParseStream</code> is the input type for all parser functions in Syn. They have
|
||
the signature <code>fn(ParseStream) -> Result<T></code>.</p>
|
||
<h3 id="calling-a-parser-function"><a class="doc-anchor" href="#calling-a-parser-function">§</a>Calling a parser function</h3>
|
||
<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="../macro.parse_macro_input.html" title="macro syn::parse_macro_input"><code>parse_macro_input!</code></a> macro if parsing input of a procedural macro;</li>
|
||
<li>One of <a href="index.html#the-synparse-functions" title="mod syn::parse">the <code>syn::parse*</code> functions</a>; or</li>
|
||
<li>A method of the <a href="trait.Parser.html" title="trait syn::parse::Parser"><code>Parser</code></a> trait.</li>
|
||
</ul>
|
||
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-ParseBuffer%3C'a%3E" class="impl"><a class="src rightside" href="../../src/syn/parse.rs.html#462-1158">source</a><a href="#impl-ParseBuffer%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.parse" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#465-467">source</a><h4 class="code-header">pub fn <a href="#method.parse" class="fn">parse</a><T: <a class="trait" href="trait.Parse.html" title="trait syn::parse::Parse">Parse</a>>(&self) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><T></h4></section></summary><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></details><details class="toggle method-toggle" open><summary><section id="method.call" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#505-507">source</a><h4 class="code-header">pub fn <a href="#method.call" class="fn">call</a><T>(
|
||
&self,
|
||
function: <a class="primitive" href="https://doc.rust-lang.org/1.82.0/std/primitive.fn.html">fn</a>(_: <a class="type" href="type.ParseStream.html" title="type syn::parse::ParseStream">ParseStream</a><'_>) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><T>,
|
||
) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><T></h4></section></summary><div class="docblock"><p>Calls the given parser function to parse a syntax tree node of type <code>T</code>
|
||
from this stream.</p>
|
||
<h5 id="example"><a class="doc-anchor" href="#example">§</a>Example</h5>
|
||
<p>The parser below invokes <a href="../struct.Attribute.html#method.parse_outer" title="associated function syn::Attribute::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"><code><span class="kw">use </span>syn::{Attribute, Ident, <span class="prelude-ty">Result</span>, Token};
|
||
<span class="kw">use </span>syn::parse::{Parse, ParseStream};
|
||
|
||
<span class="comment">// Parses a unit struct with attributes.
|
||
//
|
||
// #[path = "s.tmpl"]
|
||
// struct S;
|
||
</span><span class="kw">struct </span>UnitStruct {
|
||
attrs: Vec<Attribute>,
|
||
struct_token: <span class="macro">Token!</span>[<span class="kw">struct</span>],
|
||
name: Ident,
|
||
semi_token: <span class="macro">Token!</span>[;],
|
||
}
|
||
|
||
<span class="kw">impl </span>Parse <span class="kw">for </span>UnitStruct {
|
||
<span class="kw">fn </span>parse(input: ParseStream) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||
<span class="prelude-val">Ok</span>(UnitStruct {
|
||
attrs: input.call(Attribute::parse_outer)<span class="question-mark">?</span>,
|
||
struct_token: input.parse()<span class="question-mark">?</span>,
|
||
name: input.parse()<span class="question-mark">?</span>,
|
||
semi_token: input.parse()<span class="question-mark">?</span>,
|
||
})
|
||
}
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.peek" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#581-584">source</a><h4 class="code-header">pub fn <a href="#method.peek" class="fn">peek</a><T: <a class="trait" href="trait.Peek.html" title="trait syn::parse::Peek">Peek</a>>(&self, token: T) -> <a class="primitive" href="https://doc.rust-lang.org/1.82.0/std/primitive.bool.html">bool</a></h4></section></summary><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>
|
||
<h5 id="syntax"><a class="doc-anchor" href="#syntax">§</a>Syntax</h5>
|
||
<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(syn::Ident)</code> <em>(does not accept keywords)</em></li>
|
||
<li><code>input.peek(syn::Ident::peek_any)</code></li>
|
||
<li><code>input.peek(Lifetime)</code></li>
|
||
<li><code>input.peek(token::Brace)</code></li>
|
||
</ul>
|
||
<h5 id="example-1"><a class="doc-anchor" href="#example-1">§</a>Example</h5>
|
||
<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"><code><span class="kw">use </span>syn::{braced, token, Generics, Ident, <span class="prelude-ty">Result</span>, Token, TypeParamBound};
|
||
<span class="kw">use </span>syn::parse::{Parse, ParseStream};
|
||
<span class="kw">use </span>syn::punctuated::Punctuated;
|
||
|
||
<span class="comment">// Parses a trait definition containing no associated items.
|
||
//
|
||
// trait Marker<'de, T>: A + B<'de> where Box<T>: Clone {}
|
||
</span><span class="kw">struct </span>MarkerTrait {
|
||
trait_token: <span class="macro">Token!</span>[<span class="kw">trait</span>],
|
||
ident: Ident,
|
||
generics: Generics,
|
||
colon_token: <span class="prelude-ty">Option</span><<span class="macro">Token!</span>[:]>,
|
||
supertraits: Punctuated<TypeParamBound, <span class="macro">Token!</span>[+]>,
|
||
brace_token: token::Brace,
|
||
}
|
||
|
||
<span class="kw">impl </span>Parse <span class="kw">for </span>MarkerTrait {
|
||
<span class="kw">fn </span>parse(input: ParseStream) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||
<span class="kw">let </span>trait_token: <span class="macro">Token!</span>[<span class="kw">trait</span>] = input.parse()<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>ident: Ident = input.parse()<span class="question-mark">?</span>;
|
||
<span class="kw">let </span><span class="kw-2">mut </span>generics: Generics = input.parse()<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>colon_token: <span class="prelude-ty">Option</span><<span class="macro">Token!</span>[:]> = input.parse()<span class="question-mark">?</span>;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>supertraits = Punctuated::new();
|
||
<span class="kw">if </span>colon_token.is_some() {
|
||
<span class="kw">loop </span>{
|
||
supertraits.push_value(input.parse()<span class="question-mark">?</span>);
|
||
<span class="kw">if </span>input.peek(<span class="macro">Token!</span>[<span class="kw">where</span>]) || input.peek(token::Brace) {
|
||
<span class="kw">break</span>;
|
||
}
|
||
supertraits.push_punct(input.parse()<span class="question-mark">?</span>);
|
||
}
|
||
}
|
||
|
||
generics.where_clause = input.parse()<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>content;
|
||
<span class="kw">let </span>empty_brace_token = <span class="macro">braced!</span>(content <span class="kw">in </span>input);
|
||
|
||
<span class="prelude-val">Ok</span>(MarkerTrait {
|
||
trait_token,
|
||
ident,
|
||
generics,
|
||
colon_token,
|
||
supertraits,
|
||
brace_token: empty_brace_token,
|
||
})
|
||
}
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.peek2" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#620-627">source</a><h4 class="code-header">pub fn <a href="#method.peek2" class="fn">peek2</a><T: <a class="trait" href="trait.Peek.html" title="trait syn::parse::Peek">Peek</a>>(&self, token: T) -> <a class="primitive" href="https://doc.rust-lang.org/1.82.0/std/primitive.bool.html">bool</a></h4></section></summary><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>
|
||
<h5 id="example-2"><a class="doc-anchor" href="#example-2">§</a>Example</h5>
|
||
<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"><code><span class="kw">use </span>syn::{Ident, ItemUnion, Macro, <span class="prelude-ty">Result</span>, Token};
|
||
<span class="kw">use </span>syn::parse::{Parse, ParseStream};
|
||
|
||
<span class="comment">// Parses either a union or a macro invocation.
|
||
</span><span class="kw">enum </span>UnionOrMacro {
|
||
<span class="comment">// union MaybeUninit<T> { uninit: (), value: T }
|
||
</span>Union(ItemUnion),
|
||
<span class="comment">// lazy_static! { ... }
|
||
</span>Macro(Macro),
|
||
}
|
||
|
||
<span class="kw">impl </span>Parse <span class="kw">for </span>UnionOrMacro {
|
||
<span class="kw">fn </span>parse(input: ParseStream) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||
<span class="kw">if </span>input.peek(<span class="macro">Token!</span>[union]) && input.peek2(Ident) {
|
||
input.parse().map(UnionOrMacro::Union)
|
||
} <span class="kw">else </span>{
|
||
input.parse().map(UnionOrMacro::Macro)
|
||
}
|
||
}
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.peek3" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#630-641">source</a><h4 class="code-header">pub fn <a href="#method.peek3" class="fn">peek3</a><T: <a class="trait" href="trait.Peek.html" title="trait syn::parse::Peek">Peek</a>>(&self, token: T) -> <a class="primitive" href="https://doc.rust-lang.org/1.82.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Looks at the third-next token in the parse stream.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.parse_terminated" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#734-745">source</a><h4 class="code-header">pub fn <a href="#method.parse_terminated" class="fn">parse_terminated</a><T, P>(
|
||
&self,
|
||
parser: <a class="primitive" href="https://doc.rust-lang.org/1.82.0/std/primitive.fn.html">fn</a>(_: <a class="type" href="type.ParseStream.html" title="type syn::parse::ParseStream">ParseStream</a><'_>) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><T>,
|
||
separator: P,
|
||
) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><<a class="struct" href="../punctuated/struct.Punctuated.html" title="struct syn::punctuated::Punctuated">Punctuated</a><T, P::<a class="associatedtype" href="trait.Peek.html#associatedtype.Token" title="type syn::parse::Peek::Token">Token</a>>><div class="where">where
|
||
P: <a class="trait" href="trait.Peek.html" title="trait syn::parse::Peek">Peek</a>,
|
||
P::<a class="associatedtype" href="trait.Peek.html#associatedtype.Token" title="type syn::parse::Peek::Token">Token</a>: <a class="trait" href="trait.Parse.html" title="trait syn::parse::Parse">Parse</a>,</div></h4></section></summary><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>
|
||
<h5 id="example-3"><a class="doc-anchor" href="#example-3">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>syn::{parenthesized, token, Ident, <span class="prelude-ty">Result</span>, Token, Type};
|
||
<span class="kw">use </span>syn::parse::{Parse, ParseStream};
|
||
<span class="kw">use </span>syn::punctuated::Punctuated;
|
||
|
||
<span class="comment">// Parse a simplified tuple struct syntax like:
|
||
//
|
||
// struct S(A, B);
|
||
</span><span class="kw">struct </span>TupleStruct {
|
||
struct_token: <span class="macro">Token!</span>[<span class="kw">struct</span>],
|
||
ident: Ident,
|
||
paren_token: token::Paren,
|
||
fields: Punctuated<Type, <span class="macro">Token!</span>[,]>,
|
||
semi_token: <span class="macro">Token!</span>[;],
|
||
}
|
||
|
||
<span class="kw">impl </span>Parse <span class="kw">for </span>TupleStruct {
|
||
<span class="kw">fn </span>parse(input: ParseStream) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||
<span class="kw">let </span>content;
|
||
<span class="prelude-val">Ok</span>(TupleStruct {
|
||
struct_token: input.parse()<span class="question-mark">?</span>,
|
||
ident: input.parse()<span class="question-mark">?</span>,
|
||
paren_token: <span class="macro">parenthesized!</span>(content <span class="kw">in </span>input),
|
||
fields: content.parse_terminated(Type::parse, <span class="macro">Token!</span>[,])<span class="question-mark">?</span>,
|
||
semi_token: input.parse()<span class="question-mark">?</span>,
|
||
})
|
||
}
|
||
}</code></pre></div>
|
||
<h5 id="see-also"><a class="doc-anchor" href="#see-also">§</a>See also</h5>
|
||
<p>If your separator is anything more complicated than an invocation of the
|
||
<code>Token!</code> macro, this method won’t be applicable and you can instead
|
||
directly use <code>Punctuated</code>’s parser functions: <a href="../punctuated/struct.Punctuated.html#method.parse_terminated" title="associated function syn::punctuated::Punctuated::parse_terminated"><code>parse_terminated</code></a>,
|
||
<a href="../punctuated/struct.Punctuated.html#method.parse_separated_nonempty" title="associated function syn::punctuated::Punctuated::parse_separated_nonempty"><code>parse_separated_nonempty</code></a> etc.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>syn::{custom_keyword, Expr, <span class="prelude-ty">Result</span>, Token};
|
||
<span class="kw">use </span>syn::parse::{Parse, ParseStream};
|
||
<span class="kw">use </span>syn::punctuated::Punctuated;
|
||
|
||
<span class="kw">mod </span>kw {
|
||
<span class="macro">syn::custom_keyword!</span>(fin);
|
||
}
|
||
|
||
<span class="kw">struct </span>Fin(kw::fin, <span class="macro">Token!</span>[;]);
|
||
|
||
<span class="kw">impl </span>Parse <span class="kw">for </span>Fin {
|
||
<span class="kw">fn </span>parse(input: ParseStream) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||
<span class="prelude-val">Ok</span>(<span class="self">Self</span>(input.parse()<span class="question-mark">?</span>, input.parse()<span class="question-mark">?</span>))
|
||
}
|
||
}
|
||
|
||
<span class="kw">struct </span>Thing {
|
||
steps: Punctuated<Expr, Fin>,
|
||
}
|
||
|
||
<span class="kw">impl </span>Parse <span class="kw">for </span>Thing {
|
||
<span class="kw">fn </span>parse(input: ParseStream) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||
<span class="prelude-val">Ok</span>(Thing {
|
||
steps: Punctuated::parse_terminated(input)<span class="question-mark">?</span>,
|
||
})
|
||
<span class="comment">// or equivalently, this means the same thing:
|
||
</span>steps: input.call(Punctuated::parse_terminated)<span class="question-mark">?</span>,
|
||
}
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.is_empty" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#786-788">source</a><h4 class="code-header">pub fn <a href="#method.is_empty" class="fn">is_empty</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.82.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns whether there are no more tokens remaining to be parsed from
|
||
this stream.</p>
|
||
<p>This method returns true upon reaching the end of the content within a
|
||
set of delimiters, as well as at the end of the tokens provided to the
|
||
outermost parsing entry point.</p>
|
||
<h5 id="example-4"><a class="doc-anchor" href="#example-4">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>syn::{braced, token, Ident, Item, <span class="prelude-ty">Result</span>, Token};
|
||
<span class="kw">use </span>syn::parse::{Parse, ParseStream};
|
||
|
||
<span class="comment">// Parses a Rust `mod m { ... }` containing zero or more items.
|
||
</span><span class="kw">struct </span>Mod {
|
||
mod_token: <span class="macro">Token!</span>[<span class="kw">mod</span>],
|
||
name: Ident,
|
||
brace_token: token::Brace,
|
||
items: Vec<Item>,
|
||
}
|
||
|
||
<span class="kw">impl </span>Parse <span class="kw">for </span>Mod {
|
||
<span class="kw">fn </span>parse(input: ParseStream) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||
<span class="kw">let </span>content;
|
||
<span class="prelude-val">Ok</span>(Mod {
|
||
mod_token: input.parse()<span class="question-mark">?</span>,
|
||
name: input.parse()<span class="question-mark">?</span>,
|
||
brace_token: <span class="macro">braced!</span>(content <span class="kw">in </span>input),
|
||
items: {
|
||
<span class="kw">let </span><span class="kw-2">mut </span>items = Vec::new();
|
||
<span class="kw">while </span>!content.is_empty() {
|
||
items.push(content.parse()<span class="question-mark">?</span>);
|
||
}
|
||
items
|
||
},
|
||
})
|
||
}
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.lookahead1" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#831-833">source</a><h4 class="code-header">pub fn <a href="#method.lookahead1" class="fn">lookahead1</a>(&self) -> <a class="struct" href="struct.Lookahead1.html" title="struct syn::parse::Lookahead1">Lookahead1</a><'a></h4></section></summary><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>
|
||
<h5 id="example-5"><a class="doc-anchor" href="#example-5">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>syn::{ConstParam, Ident, Lifetime, LifetimeParam, <span class="prelude-ty">Result</span>, Token, TypeParam};
|
||
<span class="kw">use </span>syn::parse::{Parse, ParseStream};
|
||
|
||
<span class="comment">// A generic parameter, a single one of the comma-separated elements inside
|
||
// angle brackets in:
|
||
//
|
||
// fn f<T: Clone, 'a, 'b: 'a, const N: usize>() { ... }
|
||
//
|
||
// On invalid input, lookahead gives us a reasonable error message.
|
||
//
|
||
// error: expected one of: identifier, lifetime, `const`
|
||
// |
|
||
// 5 | fn f<!Sized>() {}
|
||
// | ^
|
||
</span><span class="kw">enum </span>GenericParam {
|
||
Type(TypeParam),
|
||
Lifetime(LifetimeParam),
|
||
Const(ConstParam),
|
||
}
|
||
|
||
<span class="kw">impl </span>Parse <span class="kw">for </span>GenericParam {
|
||
<span class="kw">fn </span>parse(input: ParseStream) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||
<span class="kw">let </span>lookahead = input.lookahead1();
|
||
<span class="kw">if </span>lookahead.peek(Ident) {
|
||
input.parse().map(GenericParam::Type)
|
||
} <span class="kw">else if </span>lookahead.peek(Lifetime) {
|
||
input.parse().map(GenericParam::Lifetime)
|
||
} <span class="kw">else if </span>lookahead.peek(<span class="macro">Token!</span>[<span class="kw">const</span>]) {
|
||
input.parse().map(GenericParam::Const)
|
||
} <span class="kw">else </span>{
|
||
<span class="prelude-val">Err</span>(lookahead.error())
|
||
}
|
||
}
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.fork" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#961-970">source</a><h4 class="code-header">pub fn <a href="#method.fork" class="fn">fork</a>(&self) -> Self</h4></section></summary><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>
|
||
<h5 id="performance"><a class="doc-anchor" href="#performance">§</a>Performance</h5>
|
||
<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"><code><span class="comment">// Do not do this.
|
||
</span><span class="kw">if </span>input.fork().parse::<Expr>().is_ok() {
|
||
<span class="kw">return </span>input.parse::<Expr>();
|
||
}</code></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="discouraged/trait.Speculative.html" title="trait syn::parse::discouraged::Speculative"><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="struct.ParseBuffer.html#method.step" title="method syn::parse::ParseBuffer::step"><code>ParseStream::step</code></a> instead.</p>
|
||
<h5 id="example-6"><a class="doc-anchor" href="#example-6">§</a>Example</h5>
|
||
<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"><code><span class="kw">struct </span>S(<span class="kw">pub</span>(<span class="kw">crate</span>) A, <span class="kw">pub </span>(B, C));</code></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"><code><span class="kw">use </span>syn::{parenthesized, token, Ident, Path, <span class="prelude-ty">Result</span>, Token};
|
||
<span class="kw">use </span>syn::ext::IdentExt;
|
||
<span class="kw">use </span>syn::parse::{Parse, ParseStream};
|
||
|
||
<span class="kw">struct </span>PubVisibility {
|
||
pub_token: <span class="macro">Token!</span>[<span class="kw">pub</span>],
|
||
restricted: <span class="prelude-ty">Option</span><Restricted>,
|
||
}
|
||
|
||
<span class="kw">struct </span>Restricted {
|
||
paren_token: token::Paren,
|
||
in_token: <span class="prelude-ty">Option</span><<span class="macro">Token!</span>[<span class="kw">in</span>]>,
|
||
path: Path,
|
||
}
|
||
|
||
<span class="kw">impl </span>Parse <span class="kw">for </span>PubVisibility {
|
||
<span class="kw">fn </span>parse(input: ParseStream) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||
<span class="kw">let </span>pub_token: <span class="macro">Token!</span>[<span class="kw">pub</span>] = input.parse()<span class="question-mark">?</span>;
|
||
|
||
<span class="kw">if </span>input.peek(token::Paren) {
|
||
<span class="kw">let </span>ahead = input.fork();
|
||
<span class="kw">let </span><span class="kw-2">mut </span>content;
|
||
<span class="macro">parenthesized!</span>(content <span class="kw">in </span>ahead);
|
||
|
||
<span class="kw">if </span>content.peek(<span class="macro">Token!</span>[<span class="kw">crate</span>])
|
||
|| content.peek(<span class="macro">Token!</span>[<span class="self">self</span>])
|
||
|| content.peek(<span class="macro">Token!</span>[<span class="kw">super</span>])
|
||
{
|
||
<span class="kw">return </span><span class="prelude-val">Ok</span>(PubVisibility {
|
||
pub_token,
|
||
restricted: <span class="prelude-val">Some</span>(Restricted {
|
||
paren_token: <span class="macro">parenthesized!</span>(content <span class="kw">in </span>input),
|
||
in_token: <span class="prelude-val">None</span>,
|
||
path: Path::from(content.call(Ident::parse_any)<span class="question-mark">?</span>),
|
||
}),
|
||
});
|
||
} <span class="kw">else if </span>content.peek(<span class="macro">Token!</span>[<span class="kw">in</span>]) {
|
||
<span class="kw">return </span><span class="prelude-val">Ok</span>(PubVisibility {
|
||
pub_token,
|
||
restricted: <span class="prelude-val">Some</span>(Restricted {
|
||
paren_token: <span class="macro">parenthesized!</span>(content <span class="kw">in </span>input),
|
||
in_token: <span class="prelude-val">Some</span>(content.parse()<span class="question-mark">?</span>),
|
||
path: content.call(Path::parse_mod_style)<span class="question-mark">?</span>,
|
||
}),
|
||
});
|
||
}
|
||
}
|
||
|
||
<span class="prelude-val">Ok</span>(PubVisibility {
|
||
pub_token,
|
||
restricted: <span class="prelude-val">None</span>,
|
||
})
|
||
}
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.error" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#1000-1002">source</a><h4 class="code-header">pub fn <a href="#method.error" class="fn">error</a><T: <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>>(&self, message: T) -> <a class="struct" href="struct.Error.html" title="struct syn::parse::Error">Error</a></h4></section></summary><div class="docblock"><p>Triggers an error at the current position of the parse stream.</p>
|
||
<h5 id="example-7"><a class="doc-anchor" href="#example-7">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>syn::{Expr, <span class="prelude-ty">Result</span>, Token};
|
||
<span class="kw">use </span>syn::parse::{Parse, ParseStream};
|
||
|
||
<span class="comment">// Some kind of loop: `while` or `for` or `loop`.
|
||
</span><span class="kw">struct </span>Loop {
|
||
expr: Expr,
|
||
}
|
||
|
||
<span class="kw">impl </span>Parse <span class="kw">for </span>Loop {
|
||
<span class="kw">fn </span>parse(input: ParseStream) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||
<span class="kw">if </span>input.peek(<span class="macro">Token!</span>[<span class="kw">while</span>])
|
||
|| input.peek(<span class="macro">Token!</span>[<span class="kw">for</span>])
|
||
|| input.peek(<span class="macro">Token!</span>[<span class="kw">loop</span>])
|
||
{
|
||
<span class="prelude-val">Ok</span>(Loop {
|
||
expr: input.parse()<span class="question-mark">?</span>,
|
||
})
|
||
} <span class="kw">else </span>{
|
||
<span class="prelude-val">Err</span>(input.error(<span class="string">"expected some kind of loop"</span>))
|
||
}
|
||
}
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.step" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#1049-1077">source</a><h4 class="code-header">pub fn <a href="#method.step" class="fn">step</a><F, R>(&self, function: F) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><R><div class="where">where
|
||
F: for<'c> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="struct" href="struct.StepCursor.html" title="struct syn::parse::StepCursor">StepCursor</a><'c, 'a>) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><(R, <a class="struct" href="../buffer/struct.Cursor.html" title="struct syn::buffer::Cursor">Cursor</a><'c>)>,</div></h4></section></summary><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>
|
||
<h5 id="example-8"><a class="doc-anchor" href="#example-8">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>proc_macro2::TokenTree;
|
||
<span class="kw">use </span>syn::Result;
|
||
<span class="kw">use </span>syn::parse::ParseStream;
|
||
|
||
<span class="comment">// This function advances the stream past the next occurrence of `@`. If
|
||
// no `@` is present in the stream, the stream position is unchanged and
|
||
// an error is returned.
|
||
</span><span class="kw">fn </span>skip_past_next_at(input: ParseStream) -> <span class="prelude-ty">Result</span><()> {
|
||
input.step(|cursor| {
|
||
<span class="kw">let </span><span class="kw-2">mut </span>rest = <span class="kw-2">*</span>cursor;
|
||
<span class="kw">while let </span><span class="prelude-val">Some</span>((tt, next)) = rest.token_tree() {
|
||
<span class="kw">match </span><span class="kw-2">&</span>tt {
|
||
TokenTree::Punct(punct) <span class="kw">if </span>punct.as_char() == <span class="string">'@' </span>=> {
|
||
<span class="kw">return </span><span class="prelude-val">Ok</span>(((), next));
|
||
}
|
||
<span class="kw">_ </span>=> rest = next,
|
||
}
|
||
}
|
||
<span class="prelude-val">Err</span>(cursor.error(<span class="string">"no `@` was found after this point"</span>))
|
||
})
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.span" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#1082-1089">source</a><h4 class="code-header">pub fn <a href="#method.span" class="fn">span</a>(&self) -> <a class="struct" href="../../proc_macro2/struct.Span.html" title="struct proc_macro2::Span">Span</a></h4></section></summary><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></details><details class="toggle method-toggle" open><summary><section id="method.cursor" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#1148-1150">source</a><h4 class="code-header">pub fn <a href="#method.cursor" class="fn">cursor</a>(&self) -> <a class="struct" href="../buffer/struct.Cursor.html" title="struct syn::buffer::Cursor">Cursor</a><'a></h4></section></summary><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>
|
||
<h5 id="example-9"><a class="doc-anchor" href="#example-9">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>proc_macro2::TokenStream;
|
||
<span class="kw">use </span>syn::buffer::Cursor;
|
||
<span class="kw">use </span>syn::parse::{ParseStream, <span class="prelude-ty">Result</span>};
|
||
|
||
<span class="comment">// Run a parser that returns T, but get its output as TokenStream instead of T.
|
||
// This works without T needing to implement ToTokens.
|
||
</span><span class="kw">fn </span>recognize_token_stream<T>(
|
||
recognizer: <span class="kw">fn</span>(ParseStream) -> <span class="prelude-ty">Result</span><T>,
|
||
) -> <span class="kw">impl </span>Fn(ParseStream) -> <span class="prelude-ty">Result</span><TokenStream> {
|
||
<span class="kw">move </span>|input| {
|
||
<span class="kw">let </span>begin = input.cursor();
|
||
recognizer(input)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>end = input.cursor();
|
||
<span class="prelude-val">Ok</span>(tokens_between(begin, end))
|
||
}
|
||
}
|
||
|
||
<span class="comment">// Collect tokens between two cursors as a TokenStream.
|
||
</span><span class="kw">fn </span>tokens_between(begin: Cursor, end: Cursor) -> TokenStream {
|
||
<span class="macro">assert!</span>(begin <= end);
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>cursor = begin;
|
||
<span class="kw">let </span><span class="kw-2">mut </span>tokens = TokenStream::new();
|
||
<span class="kw">while </span>cursor < end {
|
||
<span class="kw">let </span>(token, next) = cursor.token_tree().unwrap();
|
||
tokens.extend(std::iter::once(token));
|
||
cursor = next;
|
||
}
|
||
tokens
|
||
}
|
||
|
||
<span class="kw">fn </span>main() {
|
||
<span class="kw">use </span>quote::quote;
|
||
<span class="kw">use </span>syn::parse::{Parse, Parser};
|
||
<span class="kw">use </span>syn::Token;
|
||
|
||
<span class="comment">// Parse syn::Type as a TokenStream, surrounded by angle brackets.
|
||
</span><span class="kw">fn </span>example(input: ParseStream) -> <span class="prelude-ty">Result</span><TokenStream> {
|
||
<span class="kw">let </span>_langle: <span class="macro">Token!</span>[<] = input.parse()<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>ty = recognize_token_stream(syn::Type::parse)(input)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>_rangle: <span class="macro">Token!</span>[>] = input.parse()<span class="question-mark">?</span>;
|
||
<span class="prelude-val">Ok</span>(ty)
|
||
}
|
||
|
||
<span class="kw">let </span>tokens = <span class="macro">quote!</span> { <<span class="kw">fn</span>() -> u8> };
|
||
<span class="macro">println!</span>(<span class="string">"{}"</span>, example.parse2(tokens).unwrap());
|
||
}</code></pre></div>
|
||
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-AnyDelimiter-for-ParseBuffer%3C'a%3E" class="impl"><a class="src rightside" href="../../src/syn/discouraged.rs.html#211-225">source</a><a href="#impl-AnyDelimiter-for-ParseBuffer%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="discouraged/trait.AnyDelimiter.html" title="trait syn::parse::discouraged::AnyDelimiter">AnyDelimiter</a> for <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.parse_any_delimiter" class="method trait-impl"><a class="src rightside" href="../../src/syn/discouraged.rs.html#212-224">source</a><a href="#method.parse_any_delimiter" class="anchor">§</a><h4 class="code-header">fn <a href="discouraged/trait.AnyDelimiter.html#tymethod.parse_any_delimiter" class="fn">parse_any_delimiter</a>(&self) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><(<a class="enum" href="../../proc_macro2/enum.Delimiter.html" title="enum proc_macro2::Delimiter">Delimiter</a>, <a class="struct" href="../../proc_macro2/extra/struct.DelimSpan.html" title="struct proc_macro2::extra::DelimSpan">DelimSpan</a>, <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'_>)></h4></section></summary><div class='docblock'>Returns the delimiter, the span of the delimiter token, and the nested
|
||
contents for further parsing.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-ParseBuffer%3C'a%3E" class="impl"><a class="src rightside" href="../../src/syn/parse.rs.html#282-286">source</a><a href="#impl-Debug-for-ParseBuffer%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt-1" class="method trait-impl"><a class="src rightside" href="../../src/syn/parse.rs.html#283-285">source</a><a href="#method.fmt-1" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.82.0/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.82.0/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/1.82.0/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.82.0/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Display-for-ParseBuffer%3C'a%3E" class="impl"><a class="src rightside" href="../../src/syn/parse.rs.html#276-280">source</a><a href="#impl-Display-for-ParseBuffer%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> for <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="../../src/syn/parse.rs.html#277-279">source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.82.0/core/fmt/trait.Display.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.82.0/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/1.82.0/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.82.0/core/fmt/trait.Display.html#tymethod.fmt">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Drop-for-ParseBuffer%3C'a%3E" class="impl"><a class="src rightside" href="../../src/syn/parse.rs.html#264-274">source</a><a href="#impl-Drop-for-ParseBuffer%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/ops/drop/trait.Drop.html" title="trait core::ops::drop::Drop">Drop</a> for <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.drop" class="method trait-impl"><a class="src rightside" href="../../src/syn/parse.rs.html#265-273">source</a><a href="#method.drop" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.82.0/core/ops/drop/trait.Drop.html#tymethod.drop" class="fn">drop</a>(&mut self)</h4></section></summary><div class='docblock'>Executes the destructor for this type. <a href="https://doc.rust-lang.org/1.82.0/core/ops/drop/trait.Drop.html#tymethod.drop">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Speculative-for-ParseBuffer%3C'a%3E" class="impl"><a class="src rightside" href="../../src/syn/discouraged.rs.html#167-201">source</a><a href="#impl-Speculative-for-ParseBuffer%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="discouraged/trait.Speculative.html" title="trait syn::parse::discouraged::Speculative">Speculative</a> for <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.advance_to" class="method trait-impl"><a class="src rightside" href="../../src/syn/discouraged.rs.html#168-200">source</a><a href="#method.advance_to" class="anchor">§</a><h4 class="code-header">fn <a href="discouraged/trait.Speculative.html#tymethod.advance_to" class="fn">advance_to</a>(&self, fork: &Self)</h4></section></summary><div class='docblock'>Advance this parse stream to the position of a forked parse stream. <a href="discouraged/trait.Speculative.html#tymethod.advance_to">Read more</a></div></details></div></details><section id="impl-RefUnwindSafe-for-ParseBuffer%3C'a%3E" class="impl"><a class="src rightside" href="../../src/syn/parse.rs.html#289">source</a><a href="#impl-RefUnwindSafe-for-ParseBuffer%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a></h3></section><section id="impl-UnwindSafe-for-ParseBuffer%3C'a%3E" class="impl"><a class="src rightside" href="../../src/syn/parse.rs.html#288">source</a><a href="#impl-UnwindSafe-for-ParseBuffer%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a></h3></section></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-ParseBuffer%3C'a%3E" class="impl"><a href="#impl-Freeze-for-ParseBuffer%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> !<a class="trait" href="https://doc.rust-lang.org/1.82.0/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a></h3></section><section id="impl-Send-for-ParseBuffer%3C'a%3E" class="impl"><a href="#impl-Send-for-ParseBuffer%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> !<a class="trait" href="https://doc.rust-lang.org/1.82.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a></h3></section><section id="impl-Sync-for-ParseBuffer%3C'a%3E" class="impl"><a href="#impl-Sync-for-ParseBuffer%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> !<a class="trait" href="https://doc.rust-lang.org/1.82.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a></h3></section><section id="impl-Unpin-for-ParseBuffer%3C'a%3E" class="impl"><a href="#impl-Unpin-for-ParseBuffer%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/any.rs.html#138">source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
|
||
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.82.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/any.rs.html#139">source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.82.0/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.82.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.82.0/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/borrow.rs.html#209">source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/1.82.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/borrow.rs.html#211">source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.82.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.82.0/std/primitive.reference.html">&T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.82.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/borrow.rs.html#217">source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/1.82.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/borrow.rs.html#218">source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.82.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.82.0/std/primitive.reference.html">&mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.82.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/convert/mod.rs.html#765">source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/convert/mod.rs.html#768">source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.82.0/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/convert/mod.rs.html#748-750">source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/convert/mod.rs.html#758">source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.82.0/core/convert/trait.Into.html#tymethod.into" class="fn">into</a>(self) -> U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
|
||
<p>That is, this conversion is whatever the implementation of
|
||
<code><a href="https://doc.rust-lang.org/1.82.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-ToString-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/alloc/string.rs.html#2555">source</a><a href="#impl-ToString-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.82.0/alloc/string/trait.ToString.html" title="trait alloc::string::ToString">ToString</a> for T<div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.82.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.to_string" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/alloc/string.rs.html#2561">source</a><a href="#method.to_string" class="anchor">§</a><h4 class="code-header">default fn <a href="https://doc.rust-lang.org/1.82.0/alloc/string/trait.ToString.html#tymethod.to_string" class="fn">to_string</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.82.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section></summary><div class='docblock'>Converts the given value to a <code>String</code>. <a href="https://doc.rust-lang.org/1.82.0/alloc/string/trait.ToString.html#tymethod.to_string">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/convert/mod.rs.html#805-807">source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/convert/mod.rs.html#809">source</a><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.82.0/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/convert/mod.rs.html#812">source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/1.82.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/convert/mod.rs.html#790-792">source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/convert/mod.rs.html#794">source</a><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.82.0/src/core/convert/mod.rs.html#797">source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.82.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.82.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main></body></html> |