mirror of
https://github.com/NotAShelf/mpvrc.git
synced 2026-04-19 09:09:47 +00:00
deploy: de38ae62916547ad097c066f94a32e9ba7790eeb
This commit is contained in:
commit
9a86359447
28502 changed files with 1261284 additions and 0 deletions
3
syn/parse/discouraged/index.html
Normal file
3
syn/parse/discouraged/index.html
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<!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="Extensions to the parsing API with niche applicability."><title>syn::parse::discouraged - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="syn" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../syn/index.html">syn</a><span class="version">2.0.90</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module discouraged</a></h2><h3><a href="#traits">Module Items</a></h3><ul class="block"><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In syn::<wbr>parse</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">syn</a>::<wbr><a href="../index.html">parse</a></span><h1>Module <span>discouraged</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/syn/discouraged.rs.html#1-225">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extensions to the parsing API with niche applicability.</p>
|
||||
</div></details><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.AnyDelimiter.html" title="trait syn::parse::discouraged::AnyDelimiter">AnyDelimiter</a></div><div class="desc docblock-short">Extensions to the <code>ParseStream</code> API to support manipulating invisible
|
||||
delimiters the same as if they were visible.</div></li><li><div class="item-name"><a class="trait" href="trait.Speculative.html" title="trait syn::parse::discouraged::Speculative">Speculative</a></div><div class="desc docblock-short">Extensions to the <code>ParseStream</code> API to support speculative parsing.</div></li></ul></section></div></main></body></html>
|
||||
1
syn/parse/discouraged/sidebar-items.js
Normal file
1
syn/parse/discouraged/sidebar-items.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
window.SIDEBAR_ITEMS = {"trait":["AnyDelimiter","Speculative"]};
|
||||
10
syn/parse/discouraged/trait.AnyDelimiter.html
Normal file
10
syn/parse/discouraged/trait.AnyDelimiter.html
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<!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="Extensions to the `ParseStream` API to support manipulating invisible delimiters the same as if they were visible."><title>AnyDelimiter in syn::parse::discouraged - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="syn" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../syn/index.html">syn</a><span class="version">2.0.90</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">AnyDelimiter</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.parse_any_delimiter" title="parse_any_delimiter">parse_any_delimiter</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In syn::<wbr>parse::<wbr>discouraged</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">syn</a>::<wbr><a href="../index.html">parse</a>::<wbr><a href="index.html">discouraged</a></span><h1>Trait <span class="trait">AnyDelimiter</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/syn/discouraged.rs.html#205-209">Source</a> </span></div><pre class="rust item-decl"><code>pub trait AnyDelimiter {
|
||||
// Required method
|
||||
fn <a href="#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><'_>)>;
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extensions to the <code>ParseStream</code> API to support manipulating invisible
|
||||
delimiters the same as if they were visible.</p>
|
||||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.parse_any_delimiter" class="method"><a class="src rightside" href="../../../src/syn/discouraged.rs.html#208">Source</a><h4 class="code-header">fn <a href="#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"><p>Returns the delimiter, the span of the delimiter token, and the nested
|
||||
contents for further parsing.</p>
|
||||
</div></details></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><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="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></div><script src="../../../trait.impl/syn/parse/discouraged/trait.AnyDelimiter.js" async></script></section></div></main></body></html>
|
||||
107
syn/parse/discouraged/trait.Speculative.html
Normal file
107
syn/parse/discouraged/trait.Speculative.html
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
<!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="Extensions to the `ParseStream` API to support speculative parsing."><title>Speculative in syn::parse::discouraged - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="syn" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../syn/index.html">syn</a><span class="version">2.0.90</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Speculative</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.advance_to" title="advance_to">advance_to</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In syn::<wbr>parse::<wbr>discouraged</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">syn</a>::<wbr><a href="../index.html">parse</a>::<wbr><a href="index.html">discouraged</a></span><h1>Trait <span class="trait">Speculative</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/syn/discouraged.rs.html#13-165">Source</a> </span></div><pre class="rust item-decl"><code>pub trait Speculative {
|
||||
// Required method
|
||||
fn <a href="#tymethod.advance_to" class="fn">advance_to</a>(&self, fork: &Self);
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extensions to the <code>ParseStream</code> API to support speculative parsing.</p>
|
||||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.advance_to" class="method"><a class="src rightside" href="../../../src/syn/discouraged.rs.html#164">Source</a><h4 class="code-header">fn <a href="#tymethod.advance_to" class="fn">advance_to</a>(&self, fork: &Self)</h4></section></summary><div class="docblock"><p>Advance this parse stream to the position of a forked parse stream.</p>
|
||||
<p>This is the opposite operation to <a href="../struct.ParseBuffer.html#method.fork" title="method syn::parse::ParseBuffer::fork"><code>ParseStream::fork</code></a>. You can fork a
|
||||
parse stream, perform some speculative parsing, then join the original
|
||||
stream to the fork to “commit” the parsing from the fork to the main
|
||||
stream.</p>
|
||||
<p>If you can avoid doing this, you should, as it limits the ability to
|
||||
generate useful errors. That said, it is often the only way to parse
|
||||
syntax of the form <code>A* B*</code> for arbitrary syntax <code>A</code> and <code>B</code>. The problem
|
||||
is that when the fork fails to parse an <code>A</code>, it’s impossible to tell
|
||||
whether that was because of a syntax error and the user meant to provide
|
||||
an <code>A</code>, or that the <code>A</code>s are finished and it’s time to start parsing
|
||||
<code>B</code>s. Use with care.</p>
|
||||
<p>Also note that if <code>A</code> is a subset of <code>B</code>, <code>A* B*</code> can be parsed by
|
||||
parsing <code>B*</code> and removing the leading members of <code>A</code> from the
|
||||
repetition, bypassing the need to involve the downsides associated with
|
||||
speculative parsing.</p>
|
||||
<h5 id="example"><a class="doc-anchor" href="#example">§</a>Example</h5>
|
||||
<p>There has been chatter about the possibility of making the colons in the
|
||||
turbofish syntax like <code>path::to::<T></code> no longer required by accepting
|
||||
<code>path::to<T></code> in expression position. Specifically, according to <a href="https://github.com/rust-lang/rfcs/pull/2544">RFC
|
||||
2544</a>, <a href="../../struct.PathSegment.html" title="struct syn::PathSegment"><code>PathSegment</code></a> parsing should always try to consume a following
|
||||
<code><</code> token as the start of generic arguments, and reset to the <code><</code> if
|
||||
that fails (e.g. the token is acting as a less-than operator).</p>
|
||||
<p>This is the exact kind of parsing behavior which requires the “fork,
|
||||
try, commit” behavior that <a href="../struct.ParseBuffer.html#method.fork" title="method syn::parse::ParseBuffer::fork"><code>ParseStream::fork</code></a> discourages. With
|
||||
<code>advance_to</code>, we can avoid having to parse the speculatively parsed
|
||||
content a second time.</p>
|
||||
<p>This change in behavior can be implemented in syn by replacing just the
|
||||
<code>Parse</code> implementation for <code>PathSegment</code>:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>syn::parse::discouraged::Speculative;
|
||||
|
||||
<span class="kw">pub struct </span>PathSegment {
|
||||
<span class="kw">pub </span>ident: Ident,
|
||||
<span class="kw">pub </span>arguments: PathArguments,
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Parse <span class="kw">for </span>PathSegment {
|
||||
<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">super</span>])
|
||||
|| input.peek(<span class="macro">Token!</span>[<span class="self">self</span>])
|
||||
|| input.peek(<span class="macro">Token!</span>[<span class="self">Self</span>])
|
||||
|| input.peek(<span class="macro">Token!</span>[<span class="kw">crate</span>])
|
||||
{
|
||||
<span class="kw">let </span>ident = input.call(Ident::parse_any)<span class="question-mark">?</span>;
|
||||
<span class="kw">return </span><span class="prelude-val">Ok</span>(PathSegment::from(ident));
|
||||
}
|
||||
|
||||
<span class="kw">let </span>ident = input.parse()<span class="question-mark">?</span>;
|
||||
<span class="kw">if </span>input.peek(<span class="macro">Token!</span>[::]) && input.peek3(<span class="macro">Token!</span>[<]) {
|
||||
<span class="kw">return </span><span class="prelude-val">Ok</span>(PathSegment {
|
||||
ident,
|
||||
arguments: PathArguments::AngleBracketed(input.parse()<span class="question-mark">?</span>),
|
||||
});
|
||||
}
|
||||
<span class="kw">if </span>input.peek(<span class="macro">Token!</span>[<]) && !input.peek(<span class="macro">Token!</span>[<=]) {
|
||||
<span class="kw">let </span>fork = input.fork();
|
||||
<span class="kw">if let </span><span class="prelude-val">Ok</span>(arguments) = fork.parse() {
|
||||
input.advance_to(<span class="kw-2">&</span>fork);
|
||||
<span class="kw">return </span><span class="prelude-val">Ok</span>(PathSegment {
|
||||
ident,
|
||||
arguments: PathArguments::AngleBracketed(arguments),
|
||||
});
|
||||
}
|
||||
}
|
||||
<span class="prelude-val">Ok</span>(PathSegment::from(ident))
|
||||
}
|
||||
}
|
||||
</code></pre></div>
|
||||
<h5 id="drawbacks"><a class="doc-anchor" href="#drawbacks">§</a>Drawbacks</h5>
|
||||
<p>The main drawback of this style of speculative parsing is in error
|
||||
presentation. Even if the lookahead is the “correct” parse, the error
|
||||
that is shown is that of the “fallback” parse. To use the same example
|
||||
as the turbofish above, take the following unfinished “turbofish”:</p>
|
||||
<div class="example-wrap"><pre class="language-text"><code>let _ = f<&'a fn(), for<'a> serde::>();</code></pre></div>
|
||||
<p>If this is parsed as generic arguments, we can provide the error message</p>
|
||||
<div class="example-wrap"><pre class="language-text"><code>error: expected identifier
|
||||
--> src.rs:L:C
|
||||
|
|
||||
L | let _ = f<&'a fn(), for<'a> serde::>();
|
||||
| ^</code></pre></div>
|
||||
<p>but if parsed using the above speculative parsing, it falls back to
|
||||
assuming that the <code><</code> is a less-than when it fails to parse the generic
|
||||
arguments, and tries to interpret the <code>&'a</code> as the start of a labelled
|
||||
loop, resulting in the much less helpful error</p>
|
||||
<div class="example-wrap"><pre class="language-text"><code>error: expected `:`
|
||||
--> src.rs:L:C
|
||||
|
|
||||
L | let _ = f<&'a fn(), for<'a> serde::>();
|
||||
| ^^</code></pre></div>
|
||||
<p>This can be mitigated with various heuristics (two examples: show both
|
||||
forks’ parse errors, or show the one that consumed more tokens), but
|
||||
when you can control the grammar, sticking to something that can be
|
||||
parsed LL(3) and without the LL(*) speculative parsing this makes
|
||||
possible, displaying reasonable errors becomes much more simple.</p>
|
||||
<h5 id="performance"><a class="doc-anchor" href="#performance">§</a>Performance</h5>
|
||||
<p>This method performs a cheap fixed amount of work that does not depend
|
||||
on how far apart the two streams are positioned.</p>
|
||||
<h5 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h5>
|
||||
<p>The forked stream in the argument of <code>advance_to</code> must have been
|
||||
obtained by forking <code>self</code>. Attempting to advance to any other stream
|
||||
will cause a panic.</p>
|
||||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.1/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><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="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></div><script src="../../../trait.impl/syn/parse/discouraged/trait.Speculative.js" async></script></section></div></main></body></html>
|
||||
118
syn/parse/index.html
Normal file
118
syn/parse/index.html
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
<!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="Parsing interface for parsing a token stream into a syntax tree node."><title>syn::parse - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="syn" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../syn/index.html">syn</a><span class="version">2.0.90</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module parse</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li><li><a href="#the-synparse-functions" title="The `syn::parse*` functions">The <code>syn::parse*</code> functions</a></li><li><a href="#the-parser-trait" title="The `Parser` trait">The <code>Parser</code> trait</a></li></ul><h3><a href="#modules">Module Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate syn</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">syn</a></span><h1>Module <span>parse</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/syn/parse.rs.html#1-1419">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Parsing interface for parsing a token stream into a syntax tree node.</p>
|
||||
<p>Parsing in Syn is built on parser functions that take in a <a href="type.ParseStream.html" title="type syn::parse::ParseStream"><code>ParseStream</code></a>
|
||||
and produce a <a href="type.Result.html" title="type syn::parse::Result"><code>Result<T></code></a> where <code>T</code> is some syntax tree node. Underlying
|
||||
these parser functions is a lower level mechanism built around the
|
||||
<a href="../buffer/struct.Cursor.html" title="struct syn::buffer::Cursor"><code>Cursor</code></a> type. <code>Cursor</code> is a cheaply copyable cursor over a range of
|
||||
tokens in a token stream.</p>
|
||||
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
|
||||
<p>Here is a snippet of parsing code to get a feel for the style of the
|
||||
library. We define data structures for a subset of Rust syntax including
|
||||
enums (not shown) and structs, then provide implementations of the <a href="trait.Parse.html" title="trait syn::parse::Parse"><code>Parse</code></a>
|
||||
trait to parse these syntax tree data structures from a token stream.</p>
|
||||
<p>Once <code>Parse</code> impls have been defined, they can be called conveniently from a
|
||||
procedural macro through <a href="../macro.parse_macro_input.html" title="macro syn::parse_macro_input"><code>parse_macro_input!</code></a> as shown at the bottom of
|
||||
the snippet. If the caller provides syntactically invalid input to the
|
||||
procedural macro, they will receive a helpful compiler error message
|
||||
pointing out the exact token that triggered the failure to parse.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>proc_macro::TokenStream;
|
||||
<span class="kw">use </span>syn::{braced, parse_macro_input, token, Field, Ident, <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">enum </span>Item {
|
||||
Struct(ItemStruct),
|
||||
Enum(ItemEnum),
|
||||
}
|
||||
|
||||
<span class="kw">struct </span>ItemStruct {
|
||||
struct_token: <span class="macro">Token!</span>[<span class="kw">struct</span>],
|
||||
ident: Ident,
|
||||
brace_token: token::Brace,
|
||||
fields: Punctuated<Field, <span class="macro">Token!</span>[,]>,
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Parse <span class="kw">for </span>Item {
|
||||
<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(<span class="macro">Token!</span>[<span class="kw">struct</span>]) {
|
||||
input.parse().map(Item::Struct)
|
||||
} <span class="kw">else if </span>lookahead.peek(<span class="macro">Token!</span>[<span class="kw">enum</span>]) {
|
||||
input.parse().map(Item::Enum)
|
||||
} <span class="kw">else </span>{
|
||||
<span class="prelude-val">Err</span>(lookahead.error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Parse <span class="kw">for </span>ItemStruct {
|
||||
<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>(ItemStruct {
|
||||
struct_token: input.parse()<span class="question-mark">?</span>,
|
||||
ident: input.parse()<span class="question-mark">?</span>,
|
||||
brace_token: <span class="macro">braced!</span>(content <span class="kw">in </span>input),
|
||||
fields: content.parse_terminated(Field::parse_named, <span class="macro">Token!</span>[,])<span class="question-mark">?</span>,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
<span class="attr">#[proc_macro]
|
||||
</span><span class="kw">pub fn </span>my_macro(tokens: TokenStream) -> TokenStream {
|
||||
<span class="kw">let </span>input = <span class="macro">parse_macro_input!</span>(tokens <span class="kw">as </span>Item);
|
||||
|
||||
<span class="comment">/* ... */
|
||||
</span>}</code></pre></div>
|
||||
<h2 id="the-synparse-functions"><a class="doc-anchor" href="#the-synparse-functions">§</a>The <code>syn::parse*</code> functions</h2>
|
||||
<p>The <a href="../fn.parse.html" title="fn syn::parse"><code>syn::parse</code></a>, <a href="../fn.parse2.html" title="fn syn::parse2"><code>syn::parse2</code></a>, and <a href="../fn.parse_str.html" title="fn syn::parse_str"><code>syn::parse_str</code></a> functions serve
|
||||
as an entry point for parsing syntax tree nodes that can be parsed in an
|
||||
obvious default way. These functions can return any syntax tree node that
|
||||
implements the <a href="trait.Parse.html" title="trait syn::parse::Parse"><code>Parse</code></a> trait, which includes most types in Syn.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>syn::Type;
|
||||
|
||||
<span class="kw">let </span>t: Type = syn::parse_str(<span class="string">"std::collections::HashMap<String, Value>"</span>)<span class="question-mark">?</span>;</code></pre></div>
|
||||
<p>The <a href="../macro.parse_quote.html" title="macro syn::parse_quote"><code>parse_quote!</code></a> macro also uses this approach.</p>
|
||||
<h2 id="the-parser-trait"><a class="doc-anchor" href="#the-parser-trait">§</a>The <code>Parser</code> trait</h2>
|
||||
<p>Some types can be parsed in several ways depending on context. For example
|
||||
an <a href="../struct.Attribute.html" title="struct syn::Attribute"><code>Attribute</code></a> can be either “outer” like <code>#[...]</code> or “inner” like
|
||||
<code>#![...]</code> and parsing the wrong one would be a bug. Similarly <a href="../punctuated/index.html" title="mod syn::punctuated"><code>Punctuated</code></a>
|
||||
may or may not allow trailing punctuation, and parsing it the wrong way
|
||||
would either reject valid input or accept invalid input.</p>
|
||||
<p>The <code>Parse</code> trait is not implemented in these cases because there is no good
|
||||
behavior to consider the default.</p>
|
||||
|
||||
<div class="example-wrap compile_fail"><a href="#" class="tooltip" title="This example deliberately fails to compile">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="comment">// Can't parse `Punctuated` without knowing whether trailing punctuation
|
||||
// should be allowed in this context.
|
||||
</span><span class="kw">let </span>path: Punctuated<PathSegment, <span class="macro">Token!</span>[::]> = syn::parse(tokens)<span class="question-mark">?</span>;</code></pre></div>
|
||||
<p>In these cases the types provide a choice of parser functions rather than a
|
||||
single <code>Parse</code> implementation, and those parser functions can be invoked
|
||||
through the <a href="trait.Parser.html" title="trait syn::parse::Parser"><code>Parser</code></a> trait.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>proc_macro::TokenStream;
|
||||
<span class="kw">use </span>syn::parse::Parser;
|
||||
<span class="kw">use </span>syn::punctuated::Punctuated;
|
||||
<span class="kw">use </span>syn::{Attribute, Expr, PathSegment, <span class="prelude-ty">Result</span>, Token};
|
||||
|
||||
<span class="kw">fn </span>call_some_parser_methods(input: TokenStream) -> <span class="prelude-ty">Result</span><()> {
|
||||
<span class="comment">// Parse a nonempty sequence of path segments separated by `::` punctuation
|
||||
// with no trailing punctuation.
|
||||
</span><span class="kw">let </span>tokens = input.clone();
|
||||
<span class="kw">let </span>parser = Punctuated::<PathSegment, <span class="macro">Token!</span>[::]>::parse_separated_nonempty;
|
||||
<span class="kw">let </span>_path = parser.parse(tokens)<span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// Parse a possibly empty sequence of expressions terminated by commas with
|
||||
// an optional trailing punctuation.
|
||||
</span><span class="kw">let </span>tokens = input.clone();
|
||||
<span class="kw">let </span>parser = Punctuated::<Expr, <span class="macro">Token!</span>[,]>::parse_terminated;
|
||||
<span class="kw">let </span>_args = parser.parse(tokens)<span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// Parse zero or more outer attributes but not inner attributes.
|
||||
</span><span class="kw">let </span>tokens = input.clone();
|
||||
<span class="kw">let </span>parser = Attribute::parse_outer;
|
||||
<span class="kw">let </span>_attrs = parser.parse(tokens)<span class="question-mark">?</span>;
|
||||
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}</code></pre></div>
|
||||
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="discouraged/index.html" title="mod syn::parse::discouraged">discouraged</a></div><div class="desc docblock-short">Extensions to the parsing API with niche applicability.</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.End.html" title="struct syn::parse::End">End</a></div><div class="desc docblock-short">Pseudo-token used for peeking the end of a parse stream.</div></li><li><div class="item-name"><a class="struct" href="struct.Error.html" title="struct syn::parse::Error">Error</a></div><div class="desc docblock-short">Error returned when a Syn parser cannot parse the input tokens.</div></li><li><div class="item-name"><a class="struct" href="struct.Lookahead1.html" title="struct syn::parse::Lookahead1">Lookahead1</a></div><div class="desc docblock-short">Support for checking the next token in a stream to decide how to parse.</div></li><li><div class="item-name"><a class="struct" href="struct.Nothing.html" title="struct syn::parse::Nothing">Nothing</a></div><div class="desc docblock-short">An empty syntax tree node that consumes no tokens when parsed.</div></li><li><div class="item-name"><a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">Parse<wbr>Buffer</a></div><div class="desc docblock-short">Cursor position within a buffered token stream.</div></li><li><div class="item-name"><a class="struct" href="struct.StepCursor.html" title="struct syn::parse::StepCursor">Step<wbr>Cursor</a></div><div class="desc docblock-short">Cursor state associated with speculative parsing.</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.Parse.html" title="trait syn::parse::Parse">Parse</a></div><div class="desc docblock-short">Parsing interface implemented by all types that can be parsed in a default
|
||||
way from a token stream.</div></li><li><div class="item-name"><a class="trait" href="trait.Parser.html" title="trait syn::parse::Parser">Parser</a></div><div class="desc docblock-short">Parser that can parse Rust tokens into a particular syntax tree node.</div></li><li><div class="item-name"><a class="trait" href="trait.Peek.html" title="trait syn::parse::Peek">Peek</a></div><div class="desc docblock-short">Types that can be parsed by looking at just one token.</div></li></ul><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.ParseStream.html" title="type syn::parse::ParseStream">Parse<wbr>Stream</a></div><div class="desc docblock-short">Input to a Syn parser function.</div></li><li><div class="item-name"><a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a></div><div class="desc docblock-short">The result of a Syn parser.</div></li></ul></section></div></main></body></html>
|
||||
1
syn/parse/sidebar-items.js
Normal file
1
syn/parse/sidebar-items.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
window.SIDEBAR_ITEMS = {"mod":["discouraged"],"struct":["End","Error","Lookahead1","Nothing","ParseBuffer","StepCursor"],"trait":["Parse","Parser","Peek"],"type":["ParseStream","Result"]};
|
||||
117
syn/parse/struct.End.html
Normal file
117
syn/parse/struct.End.html
Normal file
File diff suppressed because one or more lines are too long
121
syn/parse/struct.Error.html
Normal file
121
syn/parse/struct.Error.html
Normal file
File diff suppressed because one or more lines are too long
70
syn/parse/struct.Lookahead1.html
Normal file
70
syn/parse/struct.Lookahead1.html
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<!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="Support for checking the next token in a stream to decide how to parse."><title>Lookahead1 in syn::parse - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="syn" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc 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.90</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Lookahead1</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li></ul><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.error" title="error">error</a></li><li><a href="#method.peek" title="peek">peek</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Freeze-for-Lookahead1%3C'a%3E" title="!Freeze">!Freeze</a></li><li><a href="#impl-RefUnwindSafe-for-Lookahead1%3C'a%3E" title="!RefUnwindSafe">!RefUnwindSafe</a></li><li><a href="#impl-Send-for-Lookahead1%3C'a%3E" title="!Send">!Send</a></li><li><a href="#impl-Sync-for-Lookahead1%3C'a%3E" title="!Sync">!Sync</a></li><li><a href="#impl-Unpin-for-Lookahead1%3C'a%3E" title="Unpin">Unpin</a></li><li><a href="#impl-UnwindSafe-for-Lookahead1%3C'a%3E" title="UnwindSafe">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T" title="Any">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T" title="Borrow<T>">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut<T>">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-T" title="From<T>">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-T" title="Into<U>">Into<U></a></li><li><a href="#impl-TryFrom%3CU%3E-for-T" title="TryFrom<U>">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-T" title="TryInto<U>">TryInto<U></a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In syn::<wbr>parse</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">syn</a>::<wbr><a href="index.html">parse</a></span><h1>Struct <span class="struct">Lookahead1</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/syn/lookahead.rs.html#62-66">Source</a> </span></div><pre class="rust item-decl"><code>pub struct Lookahead1<'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>Support for checking the next token in a stream to decide how to parse.</p>
|
||||
<p>An important advantage over <a href="struct.ParseBuffer.html#method.peek" title="method syn::parse::ParseBuffer::peek"><code>ParseStream::peek</code></a> is that here we
|
||||
automatically construct an appropriate error message based on the token
|
||||
alternatives that get peeked. If you are producing your own error message,
|
||||
go ahead and use <code>ParseStream::peek</code> instead.</p>
|
||||
<p>Use <a href="struct.ParseBuffer.html#method.lookahead1" title="method syn::parse::ParseBuffer::lookahead1"><code>ParseStream::lookahead1</code></a> to construct this object.</p>
|
||||
<p>Consuming tokens from the source stream after constructing a lookahead
|
||||
object does not also advance the lookahead object.</p>
|
||||
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
|
||||
<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><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-Lookahead1%3C'a%3E" class="impl"><a class="src rightside" href="../../src/syn/lookahead.rs.html#88-148">Source</a><a href="#impl-Lookahead1%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="struct" href="struct.Lookahead1.html" title="struct syn::parse::Lookahead1">Lookahead1</a><'a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.peek" class="method"><a class="src rightside" href="../../src/syn/lookahead.rs.html#103-106">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.84.1/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>
|
||||
<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(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>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="method.error" class="method"><a class="src rightside" href="../../src/syn/lookahead.rs.html#112-147">Source</a><h4 class="code-header">pub fn <a href="#method.error" class="fn">error</a>(self) -> <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>
|
||||
<p>The error message will identify all of the expected token types that
|
||||
have been peeked against this lookahead instance.</p>
|
||||
</div></details></div></details></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-Lookahead1%3C'a%3E" class="impl"><a href="#impl-Freeze-for-Lookahead1%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> !<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.Lookahead1.html" title="struct syn::parse::Lookahead1">Lookahead1</a><'a></h3></section><section id="impl-RefUnwindSafe-for-Lookahead1%3C'a%3E" class="impl"><a href="#impl-RefUnwindSafe-for-Lookahead1%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> !<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.Lookahead1.html" title="struct syn::parse::Lookahead1">Lookahead1</a><'a></h3></section><section id="impl-Send-for-Lookahead1%3C'a%3E" class="impl"><a href="#impl-Send-for-Lookahead1%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> !<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.Lookahead1.html" title="struct syn::parse::Lookahead1">Lookahead1</a><'a></h3></section><section id="impl-Sync-for-Lookahead1%3C'a%3E" class="impl"><a href="#impl-Sync-for-Lookahead1%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> !<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.Lookahead1.html" title="struct syn::parse::Lookahead1">Lookahead1</a><'a></h3></section><section id="impl-Unpin-for-Lookahead1%3C'a%3E" class="impl"><a href="#impl-Unpin-for-Lookahead1%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.Lookahead1.html" title="struct syn::parse::Lookahead1">Lookahead1</a><'a></h3></section><section id="impl-UnwindSafe-for-Lookahead1%3C'a%3E" class="impl"><a href="#impl-UnwindSafe-for-Lookahead1%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.Lookahead1.html" title="struct syn::parse::Lookahead1">Lookahead1</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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/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.84.1/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.84.1/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.84.1/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.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.84.1/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.84.1/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.84.1/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.84.1/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.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/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.84.1/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.84.1/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.84.1/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.84.1/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.84.1/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/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.84.1/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.84.1/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.84.1/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.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/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>
|
||||
37
syn/parse/struct.Nothing.html
Normal file
37
syn/parse/struct.Nothing.html
Normal file
File diff suppressed because one or more lines are too long
509
syn/parse/struct.ParseBuffer.html
Normal file
509
syn/parse/struct.ParseBuffer.html
Normal file
File diff suppressed because one or more lines are too long
42
syn/parse/struct.StepCursor.html
Normal file
42
syn/parse/struct.StepCursor.html
Normal file
File diff suppressed because one or more lines are too long
8
syn/parse/trait.Parse.html
Normal file
8
syn/parse/trait.Parse.html
Normal file
File diff suppressed because one or more lines are too long
25
syn/parse/trait.Parser.html
Normal file
25
syn/parse/trait.Parser.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<!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="Parser that can parse Rust tokens into a particular syntax tree node."><title>Parser in syn::parse - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="syn" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../syn/index.html">syn</a><span class="version">2.0.90</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Parser</a></h2><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Output" title="Output">Output</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.parse2" title="parse2">parse2</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.parse" title="parse">parse</a></li><li><a href="#method.parse_str" title="parse_str">parse_str</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In syn::<wbr>parse</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">syn</a>::<wbr><a href="index.html">parse</a></span><h1>Trait <span class="trait">Parser</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/syn/parse.rs.html#1239-1277">Source</a> </span></div><pre class="rust item-decl"><code>pub trait Parser: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
|
||||
type <a href="#associatedtype.Output" class="associatedtype">Output</a>;
|
||||
|
||||
// Required method
|
||||
fn <a href="#tymethod.parse2" class="fn">parse2</a>(self, tokens: <a class="struct" href="../../proc_macro2/struct.TokenStream.html" title="struct proc_macro2::TokenStream">TokenStream</a>) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><Self::<a class="associatedtype" href="trait.Parser.html#associatedtype.Output" title="type syn::parse::Parser::Output">Output</a>>;
|
||||
|
||||
// Provided methods
|
||||
fn <a href="#method.parse" class="fn">parse</a>(self, tokens: <a class="struct" href="https://doc.rust-lang.org/1.84.1/proc_macro/struct.TokenStream.html" title="struct proc_macro::TokenStream">TokenStream</a>) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><Self::<a class="associatedtype" href="trait.Parser.html#associatedtype.Output" title="type syn::parse::Parser::Output">Output</a>> { ... }
|
||||
<span class="item-spacer"></span> fn <a href="#method.parse_str" class="fn">parse_str</a>(self, s: &<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.str.html">str</a>) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><Self::<a class="associatedtype" href="trait.Parser.html#associatedtype.Output" title="type syn::parse::Parser::Output">Output</a>> { ... }
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Parser that can parse Rust tokens into a particular syntax tree node.</p>
|
||||
<p>Refer to the <a href="index.html" title="mod syn::parse">module documentation</a> for details about parsing in Syn.</p>
|
||||
</div></details><h2 id="required-associated-types" class="section-header">Required Associated Types<a href="#required-associated-types" class="anchor">§</a></h2><div class="methods"><section id="associatedtype.Output" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#1240">Source</a><h4 class="code-header">type <a href="#associatedtype.Output" class="associatedtype">Output</a></h4></section></div><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.parse2" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#1246">Source</a><h4 class="code-header">fn <a href="#tymethod.parse2" class="fn">parse2</a>(self, tokens: <a class="struct" href="../../proc_macro2/struct.TokenStream.html" title="struct proc_macro2::TokenStream">TokenStream</a>) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><Self::<a class="associatedtype" href="trait.Parser.html#associatedtype.Output" title="type syn::parse::Parser::Output">Output</a>></h4></section></summary><div class="docblock"><p>Parse a proc-macro2 token stream into the chosen syntax tree node.</p>
|
||||
<p>This function enforces that the input is fully parsed. If there are any
|
||||
unparsed tokens at the end of the stream, an error is returned.</p>
|
||||
</div></details></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.parse" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#1254-1256">Source</a><h4 class="code-header">fn <a href="#method.parse" class="fn">parse</a>(self, tokens: <a class="struct" href="https://doc.rust-lang.org/1.84.1/proc_macro/struct.TokenStream.html" title="struct proc_macro::TokenStream">TokenStream</a>) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><Self::<a class="associatedtype" href="trait.Parser.html#associatedtype.Output" title="type syn::parse::Parser::Output">Output</a>></h4></section></summary><div class="docblock"><p>Parse tokens of source code into the chosen syntax tree node.</p>
|
||||
<p>This function enforces that the input is fully parsed. If there are any
|
||||
unparsed tokens at the end of the stream, an error is returned.</p>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="method.parse_str" class="method"><a class="src rightside" href="../../src/syn/parse.rs.html#1267-1269">Source</a><h4 class="code-header">fn <a href="#method.parse_str" class="fn">parse_str</a>(self, s: &<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.str.html">str</a>) -> <a class="type" href="type.Result.html" title="type syn::parse::Result">Result</a><Self::<a class="associatedtype" href="trait.Parser.html#associatedtype.Output" title="type syn::parse::Parser::Output">Output</a>></h4></section></summary><div class="docblock"><p>Parse a string of Rust code into the chosen syntax tree node.</p>
|
||||
<p>This function enforces that the input is fully parsed. If there are any
|
||||
unparsed tokens at the end of the string, an error is returned.</p>
|
||||
<h5 id="hygiene"><a class="doc-anchor" href="#hygiene">§</a>Hygiene</h5>
|
||||
<p>Every span in the resulting syntax tree will be set to resolve at the
|
||||
macro call site.</p>
|
||||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.1/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><details class="toggle implementors-toggle"><summary><section id="impl-Parser-for-F" class="impl"><a class="src rightside" href="../../src/syn/parse.rs.html#1286-1321">Source</a><a href="#impl-Parser-for-F" class="anchor">§</a><h3 class="code-header">impl<F, T> <a class="trait" href="trait.Parser.html" title="trait syn::parse::Parser">Parser</a> for F<div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</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>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Output-1" class="associatedtype trait-impl"><a class="src rightside" href="../../src/syn/parse.rs.html#1290">Source</a><a href="#associatedtype.Output-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Output" class="associatedtype">Output</a> = T</h4></section></div></details></div><script src="../../trait.impl/syn/parse/trait.Parser.js" async></script></section></div></main></body></html>
|
||||
5
syn/parse/trait.Peek.html
Normal file
5
syn/parse/trait.Peek.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<!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="Types that can be parsed by looking at just one token."><title>Peek in syn::parse - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="syn" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../syn/index.html">syn</a><span class="version">2.0.90</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Peek</a></h2><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In syn::<wbr>parse</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">syn</a>::<wbr><a href="index.html">parse</a></span><h1>Trait <span class="trait">Peek</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/syn/lookahead.rs.html#158-162">Source</a> </span></div><pre class="rust item-decl"><code>pub trait Peek: Sealed { }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Types that can be parsed by looking at just one token.</p>
|
||||
<p>Use <a href="struct.ParseBuffer.html#method.peek" title="method syn::parse::ParseBuffer::peek"><code>ParseStream::peek</code></a> to peek one of these types in a parse stream
|
||||
without consuming it from the stream.</p>
|
||||
<p>This trait is sealed and cannot be implemented for types outside of Syn.</p>
|
||||
</div></details><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.1/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-Peek-for-End" class="impl"><a class="src rightside" href="../../src/syn/lookahead.rs.html#304-306">Source</a><a href="#impl-Peek-for-End" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Peek.html" title="trait syn::parse::Peek">Peek</a> for <a class="struct" href="struct.End.html" title="struct syn::parse::End">End</a></h3></section><section id="impl-Peek-for-F" class="impl"><a class="src rightside" href="../../src/syn/lookahead.rs.html#318-320">Source</a><a href="#impl-Peek-for-F" class="anchor">§</a><h3 class="code-header">impl<F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(TokenMarker) -> T, T: <a class="trait" href="../token/trait.Token.html" title="trait syn::token::Token">Token</a>> <a class="trait" href="trait.Peek.html" title="trait syn::parse::Peek">Peek</a> for F</h3></section></div><script src="../../trait.impl/syn/lookahead/trait.Peek.js" async></script></section></div></main></body></html>
|
||||
4
syn/parse/type.ParseStream.html
Normal file
4
syn/parse/type.ParseStream.html
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<!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="Input to a Syn parser function."><title>ParseStream in syn::parse - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="syn" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc type"><!--[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.90</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In syn::<wbr>parse</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">syn</a>::<wbr><a href="index.html">parse</a></span><h1>Type Alias <span class="type">ParseStream</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/syn/parse.rs.html#224">Source</a> </span></div><pre class="rust item-decl"><code>pub type ParseStream<'a> = &'a <a class="struct" href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer">ParseBuffer</a><'a>;</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Input to a Syn parser function.</p>
|
||||
<p>See the methods of this type under the documentation of <a href="struct.ParseBuffer.html" title="struct syn::parse::ParseBuffer"><code>ParseBuffer</code></a>. For
|
||||
an overview of parsing in Syn, refer to the <a href="index.html" title="mod syn::parse">module documentation</a>.</p>
|
||||
</div></details><script src="../../type.impl/syn/parse/struct.ParseBuffer.js" data-self-path="syn::parse::ParseStream" async></script></section></div></main></body></html>
|
||||
7
syn/parse/type.Result.html
Normal file
7
syn/parse/type.Result.html
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="The result of a Syn parser."><title>Result in syn::parse - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="syn" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc type"><!--[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.90</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Result</a></h2><h3><a href="#aliased-type">Aliased type</a></h3><h3><a href="#variants">Variants</a></h3><ul class="block variant"><li><a href="#variant.Err" title="Err">Err</a></li><li><a href="#variant.Ok" title="Ok">Ok</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In syn::<wbr>parse</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">syn</a>::<wbr><a href="index.html">parse</a></span><h1>Type Alias <span class="type">Result</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/syn/error.rs.html#14">Source</a> </span></div><pre class="rust item-decl"><code>pub type Result<T> = <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="struct" href="struct.Error.html" title="struct syn::parse::Error">Error</a>>;</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>The result of a Syn parser.</p>
|
||||
</div></details><h2 id="aliased-type" class="section-header">Aliased Type<a href="#aliased-type" class="anchor">§</a></h2><pre class="rust item-decl"><code>enum Result<T> {
|
||||
Ok(T),
|
||||
Err(<a class="struct" href="struct.Error.html" title="struct syn::parse::Error">Error</a>),
|
||||
}</code></pre><h2 id="variants" class="variants section-header">Variants<a href="#variants" class="anchor">§</a></h2><div class="variants"><section id="variant.Ok" class="variant"><a href="#variant.Ok" class="anchor">§</a><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><h3 class="code-header">Ok(T)</h3></section><div class="docblock"><p>Contains the success value</p>
|
||||
</div><section id="variant.Err" class="variant"><a href="#variant.Err" class="anchor">§</a><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><h3 class="code-header">Err(<a class="struct" href="struct.Error.html" title="struct syn::parse::Error">Error</a>)</h3></section><div class="docblock"><p>Contains the error value</p>
|
||||
</div></div><script src="../../type.impl/core/result/enum.Result.js" data-self-path="syn::error::Result" async></script></section></div></main></body></html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue