mirror of
https://github.com/trussed-dev/flexiber.git
synced 2026-06-20 04:16:10 -07:00
195 lines
40 KiB
HTML
195 lines
40 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="github crates-io docs-rs"><title>syn - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.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-84e720fa.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.89.0 (29483883e 2025-08-04)" data-channel="1.89.0" data-search-js="search-92309212.js" data-settings-js="settings-5514c975.js" ><script src="../static.files/storage-4e99c027.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-fd3af306.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-32bb7600.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 crate"><!--[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.106</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example-of-a-derive-macro" title="Example of a derive macro">Example of a derive macro</a></li><li><a href="#spans-and-error-reporting" title="Spans and error reporting">Spans and error reporting</a></li><li><a href="#parsing-a-custom-syntax" title="Parsing a custom syntax">Parsing a custom syntax</a></li><li><a href="#testing" title="Testing">Testing</a></li><li><a href="#debugging" title="Debugging">Debugging</a></li><li><a href="#optional-features" title="Optional features">Optional features</a></li></ul><h3><a href="#modules">Crate Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#macros" title="Macros">Macros</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#functions" title="Functions">Functions</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>syn</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/lib.rs.html#1-1011">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p><a href="https://github.com/dtolnay/syn"><img src="https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github" alt="github" /></a> <a href="https://crates.io/crates/syn"><img src="https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust" alt="crates-io" /></a> <a href="index.html" title="mod syn"><img src="https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" alt="docs-rs" /></a></p>
|
||
<br>
|
||
<p>Syn is a parsing library for parsing a stream of Rust tokens into a syntax
|
||
tree of Rust source code.</p>
|
||
<p>Currently this library is geared toward use in Rust procedural macros, but
|
||
contains some APIs that may be useful more generally.</p>
|
||
<ul>
|
||
<li>
|
||
<p><strong>Data structures</strong> — Syn provides a complete syntax tree that can
|
||
represent any valid Rust source code. The syntax tree is rooted at
|
||
<a href="File"><code>syn::File</code></a> which represents a full source file, but there are other
|
||
entry points that may be useful to procedural macros including
|
||
<a href="Item"><code>syn::Item</code></a>, <a href="enum.Expr.html" title="enum syn::Expr"><code>syn::Expr</code></a> and <a href="enum.Type.html" title="enum syn::Type"><code>syn::Type</code></a>.</p>
|
||
</li>
|
||
<li>
|
||
<p><strong>Derives</strong> — Of particular interest to derive macros is
|
||
<a href="struct.DeriveInput.html" title="struct syn::DeriveInput"><code>syn::DeriveInput</code></a> which is any of the three legal input items to a
|
||
derive macro. An example below shows using this type in a library that can
|
||
derive implementations of a user-defined trait.</p>
|
||
</li>
|
||
<li>
|
||
<p><strong>Parsing</strong> — Parsing in Syn is built around <a href="parse/index.html" title="mod syn::parse">parser functions</a> with the
|
||
signature <code>fn(ParseStream) -> Result<T></code>. Every syntax tree node defined
|
||
by Syn is individually parsable and may be used as a building block for
|
||
custom syntaxes, or you may dream up your own brand new syntax without
|
||
involving any of our syntax tree types.</p>
|
||
</li>
|
||
<li>
|
||
<p><strong>Location information</strong> — Every token parsed by Syn is associated with a
|
||
<code>Span</code> that tracks line and column information back to the source of that
|
||
token. These spans allow a procedural macro to display detailed error
|
||
messages pointing to all the right places in the user’s code. There is an
|
||
example of this below.</p>
|
||
</li>
|
||
<li>
|
||
<p><strong>Feature flags</strong> — Functionality is aggressively feature gated so your
|
||
procedural macros enable only what they need, and do not pay in compile
|
||
time for all the rest.</p>
|
||
</li>
|
||
</ul>
|
||
<br>
|
||
<h2 id="example-of-a-derive-macro"><a class="doc-anchor" href="#example-of-a-derive-macro">§</a>Example of a derive macro</h2>
|
||
<p>The canonical derive macro using Syn looks like this. We write an ordinary
|
||
Rust function tagged with a <code>proc_macro_derive</code> attribute and the name of
|
||
the trait we are deriving. Any time that derive appears in the user’s code,
|
||
the Rust compiler passes their data structure as tokens into our macro. We
|
||
get to execute arbitrary Rust code to figure out what to do with those
|
||
tokens, then hand some tokens back to the compiler to compile into the
|
||
user’s crate.</p>
|
||
<div class="example-wrap"><pre class="language-toml"><code>[dependencies]
|
||
syn = "2.0"
|
||
quote = "1.0"
|
||
|
||
[lib]
|
||
proc-macro = true</code></pre></div>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>proc_macro::TokenStream;
|
||
<span class="kw">use </span>quote::quote;
|
||
<span class="kw">use </span>syn::{parse_macro_input, DeriveInput};
|
||
|
||
<span class="attr">#[proc_macro_derive(MyMacro)]
|
||
</span><span class="kw">pub fn </span>my_macro(input: TokenStream) -> TokenStream {
|
||
<span class="comment">// Parse the input tokens into a syntax tree
|
||
</span><span class="kw">let </span>input = <span class="macro">parse_macro_input!</span>(input <span class="kw">as </span>DeriveInput);
|
||
|
||
<span class="comment">// Build the output, possibly using quasi-quotation
|
||
</span><span class="kw">let </span>expanded = <span class="macro">quote!</span> {
|
||
<span class="comment">// ...
|
||
</span>};
|
||
|
||
<span class="comment">// Hand the output tokens back to the compiler
|
||
</span>TokenStream::from(expanded)
|
||
}</code></pre></div>
|
||
<p>The <a href="https://github.com/dtolnay/syn/tree/master/examples/heapsize"><code>heapsize</code></a> example directory shows a complete working implementation
|
||
of a derive macro. The example derives a <code>HeapSize</code> trait which computes an
|
||
estimate of the amount of heap memory owned by a value.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">pub trait </span>HeapSize {
|
||
<span class="doccomment">/// Total number of bytes of heap memory owned by `self`.
|
||
</span><span class="kw">fn </span>heap_size_of_children(<span class="kw-2">&</span><span class="self">self</span>) -> usize;
|
||
}</code></pre></div>
|
||
<p>The derive macro allows users to write <code>#[derive(HeapSize)]</code> on data
|
||
structures in their program.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[derive(HeapSize)]
|
||
</span><span class="kw">struct </span>Demo<<span class="lifetime">'a</span>, T: <span class="question-mark">?</span>Sized> {
|
||
a: Box<T>,
|
||
b: u8,
|
||
c: <span class="kw-2">&</span><span class="lifetime">'a </span>str,
|
||
d: String,
|
||
}</code></pre></div>
|
||
<p><br></p>
|
||
<h2 id="spans-and-error-reporting"><a class="doc-anchor" href="#spans-and-error-reporting">§</a>Spans and error reporting</h2>
|
||
<p>The token-based procedural macro API provides great control over where the
|
||
compiler’s error messages are displayed in user code. Consider the error the
|
||
user sees if one of their field types does not implement <code>HeapSize</code>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[derive(HeapSize)]
|
||
</span><span class="kw">struct </span>Broken {
|
||
ok: String,
|
||
bad: std::thread::Thread,
|
||
}</code></pre></div>
|
||
<p>By tracking span information all the way through the expansion of a
|
||
procedural macro as shown in the <code>heapsize</code> example, token-based macros in
|
||
Syn are able to trigger errors that directly pinpoint the source of the
|
||
problem.</p>
|
||
<div class="example-wrap"><pre class="language-text"><code>error[E0277]: the trait bound `std::thread::Thread: HeapSize` is not satisfied
|
||
--> src/main.rs:7:5
|
||
|
|
||
7 | bad: std::thread::Thread,
|
||
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `HeapSize` is not implemented for `Thread`</code></pre></div><br>
|
||
<h2 id="parsing-a-custom-syntax"><a class="doc-anchor" href="#parsing-a-custom-syntax">§</a>Parsing a custom syntax</h2>
|
||
<p>The <a href="https://github.com/dtolnay/syn/tree/master/examples/lazy-static"><code>lazy-static</code></a> example directory shows the implementation of a
|
||
<code>functionlike!(...)</code> procedural macro in which the input tokens are parsed
|
||
using Syn’s parsing API.</p>
|
||
<p>The example reimplements the popular <code>lazy_static</code> crate from crates.io as a
|
||
procedural macro.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">lazy_static!</span> {
|
||
<span class="kw">static </span><span class="kw-2">ref </span>USERNAME: Regex = Regex::new(<span class="string">"^[a-z0-9_-]{3,16}$"</span>).unwrap();
|
||
}</code></pre></div>
|
||
<p>The implementation shows how to trigger custom warnings and error messages
|
||
on the macro input.</p>
|
||
<div class="example-wrap"><pre class="language-text"><code>warning: come on, pick a more creative name
|
||
--> src/main.rs:10:16
|
||
|
|
||
10 | static ref FOO: String = "lazy_static".to_owned();
|
||
| ^^^</code></pre></div><br>
|
||
<h2 id="testing"><a class="doc-anchor" href="#testing">§</a>Testing</h2>
|
||
<p>When testing macros, we often care not just that the macro can be used
|
||
successfully but also that when the macro is provided with invalid input it
|
||
produces maximally helpful error messages. Consider using the <a href="https://github.com/dtolnay/trybuild"><code>trybuild</code></a>
|
||
crate to write tests for errors that are emitted by your macro or errors
|
||
detected by the Rust compiler in the expanded code following misuse of the
|
||
macro. Such tests help avoid regressions from later refactors that
|
||
mistakenly make an error no longer trigger or be less helpful than it used
|
||
to be.</p>
|
||
<br>
|
||
<h2 id="debugging"><a class="doc-anchor" href="#debugging">§</a>Debugging</h2>
|
||
<p>When developing a procedural macro it can be helpful to look at what the
|
||
generated code looks like. Use <code>cargo rustc -- -Zunstable-options --pretty=expanded</code> or the <a href="https://github.com/dtolnay/cargo-expand"><code>cargo expand</code></a> subcommand.</p>
|
||
<p>To show the expanded code for some crate that uses your procedural macro,
|
||
run <code>cargo expand</code> from that crate. To show the expanded code for one of
|
||
your own test cases, run <code>cargo expand --test the_test_case</code> where the last
|
||
argument is the name of the test file without the <code>.rs</code> extension.</p>
|
||
<p>This write-up by Brandon W Maister discusses debugging in more detail:
|
||
<a href="https://quodlibetor.github.io/posts/debugging-rusts-new-custom-derive-system/">Debugging Rust’s new Custom Derive system</a>.</p>
|
||
<br>
|
||
<h2 id="optional-features"><a class="doc-anchor" href="#optional-features">§</a>Optional features</h2>
|
||
<p>Syn puts a lot of functionality behind optional features in order to
|
||
optimize compile time for the most common use cases. The following features
|
||
are available.</p>
|
||
<ul>
|
||
<li><strong><code>derive</code></strong> <em>(enabled by default)</em> — Data structures for representing the
|
||
possible input to a derive macro, including structs and enums and types.</li>
|
||
<li><strong><code>full</code></strong> — Data structures for representing the syntax tree of all valid
|
||
Rust source code, including items and expressions.</li>
|
||
<li><strong><code>parsing</code></strong> <em>(enabled by default)</em> — Ability to parse input tokens into
|
||
a syntax tree node of a chosen type.</li>
|
||
<li><strong><code>printing</code></strong> <em>(enabled by default)</em> — Ability to print a syntax tree
|
||
node as tokens of Rust source code.</li>
|
||
<li><strong><code>visit</code></strong> — Trait for traversing a syntax tree.</li>
|
||
<li><strong><code>visit-mut</code></strong> — Trait for traversing and mutating in place a syntax
|
||
tree.</li>
|
||
<li><strong><code>fold</code></strong> — Trait for transforming an owned syntax tree.</li>
|
||
<li><strong><code>clone-impls</code></strong> <em>(enabled by default)</em> — Clone impls for all syntax tree
|
||
types.</li>
|
||
<li><strong><code>extra-traits</code></strong> — Debug, Eq, PartialEq, Hash impls for all syntax tree
|
||
types.</li>
|
||
<li><strong><code>proc-macro</code></strong> <em>(enabled by default)</em> — Runtime dependency on the
|
||
dynamic library libproc_macro from rustc toolchain.</li>
|
||
</ul>
|
||
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><dl class="item-table"><dt><a class="mod" href="buffer/index.html" title="mod syn::buffer">buffer</a></dt><dd>A stably addressed token buffer supporting efficient traversal based on a
|
||
cheaply copyable cursor.</dd><dt><a class="mod" href="ext/index.html" title="mod syn::ext">ext</a></dt><dd>Extension traits to provide parsing methods on foreign types.</dd><dt><a class="mod" href="meta/index.html" title="mod syn::meta">meta</a></dt><dd>Facility for interpreting structured content inside of an <code>Attribute</code>.</dd><dt><a class="mod" href="parse/index.html" title="mod syn::parse">parse</a></dt><dd>Parsing interface for parsing a token stream into a syntax tree node.</dd><dt><a class="mod" href="punctuated/index.html" title="mod syn::punctuated">punctuated</a></dt><dd>A punctuated sequence of syntax tree nodes separated by punctuation.</dd><dt><a class="mod" href="spanned/index.html" title="mod syn::spanned">spanned</a></dt><dd>A trait that can provide the <code>Span</code> of the complete contents of a syntax
|
||
tree node.</dd><dt><a class="mod" href="token/index.html" title="mod syn::token">token</a></dt><dd>Tokens representing Rust punctuation, keywords, and delimiters.</dd><dt><a class="mod" href="visit/index.html" title="mod syn::visit">visit</a></dt><dd>Syntax tree traversal to walk a shared borrow of a syntax tree.</dd></dl><h2 id="macros" class="section-header">Macros<a href="#macros" class="anchor">§</a></h2><dl class="item-table"><dt><a class="macro" href="macro.Token.html" title="macro syn::Token">Token</a></dt><dd>A type-macro that expands to the name of the Rust type representation of a
|
||
given token.</dd><dt><a class="macro" href="macro.braced.html" title="macro syn::braced">braced</a></dt><dd>Parse a set of curly braces and expose their content to subsequent parsers.</dd><dt><a class="macro" href="macro.bracketed.html" title="macro syn::bracketed">bracketed</a></dt><dd>Parse a set of square brackets and expose their content to subsequent
|
||
parsers.</dd><dt><a class="macro" href="macro.custom_keyword.html" title="macro syn::custom_keyword">custom_<wbr>keyword</a></dt><dd>Define a type that supports parsing and printing a given identifier as if it
|
||
were a keyword.</dd><dt><a class="macro" href="macro.custom_punctuation.html" title="macro syn::custom_punctuation">custom_<wbr>punctuation</a></dt><dd>Define a type that supports parsing and printing a multi-character symbol
|
||
as if it were a punctuation token.</dd><dt><a class="macro" href="macro.parenthesized.html" title="macro syn::parenthesized">parenthesized</a></dt><dd>Parse a set of parentheses and expose their content to subsequent parsers.</dd><dt><a class="macro" href="macro.parse_macro_input.html" title="macro syn::parse_macro_input">parse_<wbr>macro_<wbr>input</a></dt><dd>Parse the input TokenStream of a macro, triggering a compile error if the
|
||
tokens fail to parse.</dd><dt><a class="macro" href="macro.parse_quote.html" title="macro syn::parse_quote">parse_<wbr>quote</a></dt><dd>Quasi-quotation macro that accepts input like the <a href="https://docs.rs/quote/1.0/quote/index.html"><code>quote!</code></a> macro but uses
|
||
type inference to figure out a return type for those tokens.</dd><dt><a class="macro" href="macro.parse_quote_spanned.html" title="macro syn::parse_quote_spanned">parse_<wbr>quote_<wbr>spanned</a></dt><dd>This macro is <a href="macro.parse_quote.html" title="macro syn::parse_quote"><code>parse_quote!</code></a> + <a href="../quote/macro.quote_spanned.html" title="macro quote::quote_spanned"><code>quote_spanned!</code></a>.</dd></dl><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.Abi.html" title="struct syn::Abi">Abi</a></dt><dd>The binary interface of a function: <code>extern "C"</code>.</dd><dt><a class="struct" href="struct.AngleBracketedGenericArguments.html" title="struct syn::AngleBracketedGenericArguments">Angle<wbr>Bracketed<wbr>Generic<wbr>Arguments</a></dt><dd>Angle bracketed arguments of a path segment: the <code><K, V></code> in <code>HashMap<K, V></code>.</dd><dt><a class="struct" href="struct.AssocConst.html" title="struct syn::AssocConst">Assoc<wbr>Const</a></dt><dd>An equality constraint on an associated constant: the <code>PANIC = false</code> in
|
||
<code>Trait<PANIC = false></code>.</dd><dt><a class="struct" href="struct.AssocType.html" title="struct syn::AssocType">Assoc<wbr>Type</a></dt><dd>A binding (equality constraint) on an associated type: the <code>Item = u8</code>
|
||
in <code>Iterator<Item = u8></code>.</dd><dt><a class="struct" href="struct.Attribute.html" title="struct syn::Attribute">Attribute</a></dt><dd>An attribute, like <code>#[repr(transparent)]</code>.</dd><dt><a class="struct" href="struct.BareFnArg.html" title="struct syn::BareFnArg">Bare<wbr>FnArg</a></dt><dd>An argument in a function type: the <code>usize</code> in <code>fn(usize) -> bool</code>.</dd><dt><a class="struct" href="struct.BareVariadic.html" title="struct syn::BareVariadic">Bare<wbr>Variadic</a></dt><dd>The variadic argument of a function pointer like <code>fn(usize, ...)</code>.</dd><dt><a class="struct" href="struct.BoundLifetimes.html" title="struct syn::BoundLifetimes">Bound<wbr>Lifetimes</a></dt><dd>A set of bound lifetimes: <code>for<'a, 'b, 'c></code>.</dd><dt><a class="struct" href="struct.ConstParam.html" title="struct syn::ConstParam">Const<wbr>Param</a></dt><dd>A const generic parameter: <code>const LENGTH: usize</code>.</dd><dt><a class="struct" href="struct.Constraint.html" title="struct syn::Constraint">Constraint</a></dt><dd>An associated type bound: <code>Iterator<Item: Display></code>.</dd><dt><a class="struct" href="struct.DataEnum.html" title="struct syn::DataEnum">Data<wbr>Enum</a></dt><dd>An enum input to a <code>proc_macro_derive</code> macro.</dd><dt><a class="struct" href="struct.DataStruct.html" title="struct syn::DataStruct">Data<wbr>Struct</a></dt><dd>A struct input to a <code>proc_macro_derive</code> macro.</dd><dt><a class="struct" href="struct.DataUnion.html" title="struct syn::DataUnion">Data<wbr>Union</a></dt><dd>An untagged union input to a <code>proc_macro_derive</code> macro.</dd><dt><a class="struct" href="struct.DeriveInput.html" title="struct syn::DeriveInput">Derive<wbr>Input</a></dt><dd>Data structure sent to a <code>proc_macro_derive</code> macro.</dd><dt><a class="struct" href="struct.Error.html" title="struct syn::Error">Error</a></dt><dd>Error returned when a Syn parser cannot parse the input tokens.</dd><dt><a class="struct" href="struct.ExprArray.html" title="struct syn::ExprArray">Expr<wbr>Array</a></dt><dd>A slice literal expression: <code>[a, b, c, d]</code>.</dd><dt><a class="struct" href="struct.ExprAssign.html" title="struct syn::ExprAssign">Expr<wbr>Assign</a></dt><dd>An assignment expression: <code>a = compute()</code>.</dd><dt><a class="struct" href="struct.ExprAsync.html" title="struct syn::ExprAsync">Expr<wbr>Async</a></dt><dd>An async block: <code>async { ... }</code>.</dd><dt><a class="struct" href="struct.ExprAwait.html" title="struct syn::ExprAwait">Expr<wbr>Await</a></dt><dd>An await expression: <code>fut.await</code>.</dd><dt><a class="struct" href="struct.ExprBinary.html" title="struct syn::ExprBinary">Expr<wbr>Binary</a></dt><dd>A binary operation: <code>a + b</code>, <code>a += b</code>.</dd><dt><a class="struct" href="struct.ExprBlock.html" title="struct syn::ExprBlock">Expr<wbr>Block</a></dt><dd>A blocked scope: <code>{ ... }</code>.</dd><dt><a class="struct" href="struct.ExprBreak.html" title="struct syn::ExprBreak">Expr<wbr>Break</a></dt><dd>A <code>break</code>, with an optional label to break and an optional
|
||
expression.</dd><dt><a class="struct" href="struct.ExprCall.html" title="struct syn::ExprCall">Expr<wbr>Call</a></dt><dd>A function call expression: <code>invoke(a, b)</code>.</dd><dt><a class="struct" href="struct.ExprCast.html" title="struct syn::ExprCast">Expr<wbr>Cast</a></dt><dd>A cast expression: <code>foo as f64</code>.</dd><dt><a class="struct" href="struct.ExprClosure.html" title="struct syn::ExprClosure">Expr<wbr>Closure</a></dt><dd>A closure expression: <code>|a, b| a + b</code>.</dd><dt><a class="struct" href="struct.ExprConst.html" title="struct syn::ExprConst">Expr<wbr>Const</a></dt><dd>A const block: <code>const { ... }</code>.</dd><dt><a class="struct" href="struct.ExprContinue.html" title="struct syn::ExprContinue">Expr<wbr>Continue</a></dt><dd>A <code>continue</code>, with an optional label.</dd><dt><a class="struct" href="struct.ExprField.html" title="struct syn::ExprField">Expr<wbr>Field</a></dt><dd>Access of a named struct field (<code>obj.k</code>) or unnamed tuple struct
|
||
field (<code>obj.0</code>).</dd><dt><a class="struct" href="struct.ExprForLoop.html" title="struct syn::ExprForLoop">Expr<wbr>ForLoop</a></dt><dd>A for loop: <code>for pat in expr { ... }</code>.</dd><dt><a class="struct" href="struct.ExprGroup.html" title="struct syn::ExprGroup">Expr<wbr>Group</a></dt><dd>An expression contained within invisible delimiters.</dd><dt><a class="struct" href="struct.ExprIf.html" title="struct syn::ExprIf">ExprIf</a></dt><dd>An <code>if</code> expression with an optional <code>else</code> block: <code>if expr { ... } else { ... }</code>.</dd><dt><a class="struct" href="struct.ExprIndex.html" title="struct syn::ExprIndex">Expr<wbr>Index</a></dt><dd>A square bracketed indexing expression: <code>vector[2]</code>.</dd><dt><a class="struct" href="struct.ExprInfer.html" title="struct syn::ExprInfer">Expr<wbr>Infer</a></dt><dd>The inferred value of a const generic argument, denoted <code>_</code>.</dd><dt><a class="struct" href="struct.ExprLet.html" title="struct syn::ExprLet">ExprLet</a></dt><dd>A <code>let</code> guard: <code>let Some(x) = opt</code>.</dd><dt><a class="struct" href="struct.ExprLit.html" title="struct syn::ExprLit">ExprLit</a></dt><dd>A literal in place of an expression: <code>1</code>, <code>"foo"</code>.</dd><dt><a class="struct" href="struct.ExprLoop.html" title="struct syn::ExprLoop">Expr<wbr>Loop</a></dt><dd>Conditionless loop: <code>loop { ... }</code>.</dd><dt><a class="struct" href="struct.ExprMacro.html" title="struct syn::ExprMacro">Expr<wbr>Macro</a></dt><dd>A macro invocation expression: <code>format!("{}", q)</code>.</dd><dt><a class="struct" href="struct.ExprMatch.html" title="struct syn::ExprMatch">Expr<wbr>Match</a></dt><dd>A <code>match</code> expression: <code>match n { Some(n) => {}, None => {} }</code>.</dd><dt><a class="struct" href="struct.ExprMethodCall.html" title="struct syn::ExprMethodCall">Expr<wbr>Method<wbr>Call</a></dt><dd>A method call expression: <code>x.foo::<T>(a, b)</code>.</dd><dt><a class="struct" href="struct.ExprParen.html" title="struct syn::ExprParen">Expr<wbr>Paren</a></dt><dd>A parenthesized expression: <code>(a + b)</code>.</dd><dt><a class="struct" href="struct.ExprPath.html" title="struct syn::ExprPath">Expr<wbr>Path</a></dt><dd>A path like <code>std::mem::replace</code> possibly containing generic
|
||
parameters and a qualified self-type.</dd><dt><a class="struct" href="struct.ExprRange.html" title="struct syn::ExprRange">Expr<wbr>Range</a></dt><dd>A range expression: <code>1..2</code>, <code>1..</code>, <code>..2</code>, <code>1..=2</code>, <code>..=2</code>.</dd><dt><a class="struct" href="struct.ExprRawAddr.html" title="struct syn::ExprRawAddr">Expr<wbr>RawAddr</a></dt><dd>Address-of operation: <code>&raw const place</code> or <code>&raw mut place</code>.</dd><dt><a class="struct" href="struct.ExprReference.html" title="struct syn::ExprReference">Expr<wbr>Reference</a></dt><dd>A referencing operation: <code>&a</code> or <code>&mut a</code>.</dd><dt><a class="struct" href="struct.ExprRepeat.html" title="struct syn::ExprRepeat">Expr<wbr>Repeat</a></dt><dd>An array literal constructed from one repeated element: <code>[0u8; N]</code>.</dd><dt><a class="struct" href="struct.ExprReturn.html" title="struct syn::ExprReturn">Expr<wbr>Return</a></dt><dd>A <code>return</code>, with an optional value to be returned.</dd><dt><a class="struct" href="struct.ExprStruct.html" title="struct syn::ExprStruct">Expr<wbr>Struct</a></dt><dd>A struct literal expression: <code>Point { x: 1, y: 1 }</code>.</dd><dt><a class="struct" href="struct.ExprTry.html" title="struct syn::ExprTry">ExprTry</a></dt><dd>A try-expression: <code>expr?</code>.</dd><dt><a class="struct" href="struct.ExprTryBlock.html" title="struct syn::ExprTryBlock">Expr<wbr>TryBlock</a></dt><dd>A try block: <code>try { ... }</code>.</dd><dt><a class="struct" href="struct.ExprTuple.html" title="struct syn::ExprTuple">Expr<wbr>Tuple</a></dt><dd>A tuple expression: <code>(a, b, c, d)</code>.</dd><dt><a class="struct" href="struct.ExprUnary.html" title="struct syn::ExprUnary">Expr<wbr>Unary</a></dt><dd>A unary operation: <code>!x</code>, <code>*x</code>.</dd><dt><a class="struct" href="struct.ExprUnsafe.html" title="struct syn::ExprUnsafe">Expr<wbr>Unsafe</a></dt><dd>An unsafe block: <code>unsafe { ... }</code>.</dd><dt><a class="struct" href="struct.ExprWhile.html" title="struct syn::ExprWhile">Expr<wbr>While</a></dt><dd>A while loop: <code>while expr { ... }</code>.</dd><dt><a class="struct" href="struct.ExprYield.html" title="struct syn::ExprYield">Expr<wbr>Yield</a></dt><dd>A yield expression: <code>yield expr</code>.</dd><dt><a class="struct" href="struct.Field.html" title="struct syn::Field">Field</a></dt><dd>A field of a struct or enum variant.</dd><dt><a class="struct" href="struct.FieldValue.html" title="struct syn::FieldValue">Field<wbr>Value</a></dt><dd>A field-value pair in a struct literal.</dd><dt><a class="struct" href="struct.FieldsNamed.html" title="struct syn::FieldsNamed">Fields<wbr>Named</a></dt><dd>Named fields of a struct or struct variant such as <code>Point { x: f64, y: f64 }</code>.</dd><dt><a class="struct" href="struct.FieldsUnnamed.html" title="struct syn::FieldsUnnamed">Fields<wbr>Unnamed</a></dt><dd>Unnamed fields of a tuple struct or tuple variant such as <code>Some(T)</code>.</dd><dt><a class="struct" href="struct.Generics.html" title="struct syn::Generics">Generics</a></dt><dd>Lifetimes and type parameters attached to a declaration of a function,
|
||
enum, trait, etc.</dd><dt><a class="struct" href="struct.Ident.html" title="struct syn::Ident">Ident</a></dt><dd>A word of Rust code, which may be a keyword or legal variable name.</dd><dt><a class="struct" href="struct.ImplGenerics.html" title="struct syn::ImplGenerics">Impl<wbr>Generics</a></dt><dd>Returned by <code>Generics::split_for_impl</code>.</dd><dt><a class="struct" href="struct.Index.html" title="struct syn::Index">Index</a></dt><dd>The index of an unnamed tuple struct field.</dd><dt><a class="struct" href="struct.Lifetime.html" title="struct syn::Lifetime">Lifetime</a></dt><dd>A Rust lifetime: <code>'a</code>.</dd><dt><a class="struct" href="struct.LifetimeParam.html" title="struct syn::LifetimeParam">Lifetime<wbr>Param</a></dt><dd>A lifetime definition: <code>'a: 'b + 'c + 'd</code>.</dd><dt><a class="struct" href="struct.LitBool.html" title="struct syn::LitBool">LitBool</a></dt><dd>A boolean literal: <code>true</code> or <code>false</code>.</dd><dt><a class="struct" href="struct.LitByte.html" title="struct syn::LitByte">LitByte</a></dt><dd>A byte literal: <code>b'f'</code>.</dd><dt><a class="struct" href="struct.LitByteStr.html" title="struct syn::LitByteStr">LitByte<wbr>Str</a></dt><dd>A byte string literal: <code>b"foo"</code>.</dd><dt><a class="struct" href="struct.LitCStr.html" title="struct syn::LitCStr">LitCStr</a></dt><dd>A nul-terminated C-string literal: <code>c"foo"</code>.</dd><dt><a class="struct" href="struct.LitChar.html" title="struct syn::LitChar">LitChar</a></dt><dd>A character literal: <code>'a'</code>.</dd><dt><a class="struct" href="struct.LitFloat.html" title="struct syn::LitFloat">LitFloat</a></dt><dd>A floating point literal: <code>1f64</code> or <code>1.0e10f64</code>.</dd><dt><a class="struct" href="struct.LitInt.html" title="struct syn::LitInt">LitInt</a></dt><dd>An integer literal: <code>1</code> or <code>1u16</code>.</dd><dt><a class="struct" href="struct.LitStr.html" title="struct syn::LitStr">LitStr</a></dt><dd>A UTF-8 string literal: <code>"foo"</code>.</dd><dt><a class="struct" href="struct.Macro.html" title="struct syn::Macro">Macro</a></dt><dd>A macro invocation: <code>println!("{}", mac)</code>.</dd><dt><a class="struct" href="struct.MetaList.html" title="struct syn::MetaList">Meta<wbr>List</a></dt><dd>A structured list within an attribute, like <code>derive(Copy, Clone)</code>.</dd><dt><a class="struct" href="struct.MetaNameValue.html" title="struct syn::MetaNameValue">Meta<wbr>Name<wbr>Value</a></dt><dd>A name-value pair within an attribute, like <code>feature = "nightly"</code>.</dd><dt><a class="struct" href="struct.ParenthesizedGenericArguments.html" title="struct syn::ParenthesizedGenericArguments">Parenthesized<wbr>Generic<wbr>Arguments</a></dt><dd>Arguments of a function path segment: the <code>(A, B) -> C</code> in <code>Fn(A,B) -> C</code>.</dd><dt><a class="struct" href="struct.Path.html" title="struct syn::Path">Path</a></dt><dd>A path at which a named item is exported (e.g. <code>std::collections::HashMap</code>).</dd><dt><a class="struct" href="struct.PathSegment.html" title="struct syn::PathSegment">Path<wbr>Segment</a></dt><dd>A segment of a path together with any path arguments on that segment.</dd><dt><a class="struct" href="struct.PredicateLifetime.html" title="struct syn::PredicateLifetime">Predicate<wbr>Lifetime</a></dt><dd>A lifetime predicate in a <code>where</code> clause: <code>'a: 'b + 'c</code>.</dd><dt><a class="struct" href="struct.PredicateType.html" title="struct syn::PredicateType">Predicate<wbr>Type</a></dt><dd>A type predicate in a <code>where</code> clause: <code>for<'c> Foo<'c>: Trait<'c></code>.</dd><dt><a class="struct" href="struct.QSelf.html" title="struct syn::QSelf">QSelf</a></dt><dd>The explicit Self type in a qualified path: the <code>T</code> in <code><T as Display>::fmt</code>.</dd><dt><a class="struct" href="struct.TraitBound.html" title="struct syn::TraitBound">Trait<wbr>Bound</a></dt><dd>A trait used as a bound on a type parameter.</dd><dt><a class="struct" href="struct.Turbofish.html" title="struct syn::Turbofish">Turbofish</a></dt><dd>Returned by <code>TypeGenerics::as_turbofish</code>.</dd><dt><a class="struct" href="struct.TypeArray.html" title="struct syn::TypeArray">Type<wbr>Array</a></dt><dd>A fixed size array type: <code>[T; n]</code>.</dd><dt><a class="struct" href="struct.TypeBareFn.html" title="struct syn::TypeBareFn">Type<wbr>Bare<wbr>Fn</a></dt><dd>A bare function type: <code>fn(usize) -> bool</code>.</dd><dt><a class="struct" href="struct.TypeGenerics.html" title="struct syn::TypeGenerics">Type<wbr>Generics</a></dt><dd>Returned by <code>Generics::split_for_impl</code>.</dd><dt><a class="struct" href="struct.TypeGroup.html" title="struct syn::TypeGroup">Type<wbr>Group</a></dt><dd>A type contained within invisible delimiters.</dd><dt><a class="struct" href="struct.TypeImplTrait.html" title="struct syn::TypeImplTrait">Type<wbr>Impl<wbr>Trait</a></dt><dd>An <code>impl Bound1 + Bound2 + Bound3</code> type where <code>Bound</code> is a trait or
|
||
a lifetime.</dd><dt><a class="struct" href="struct.TypeInfer.html" title="struct syn::TypeInfer">Type<wbr>Infer</a></dt><dd>Indication that a type should be inferred by the compiler: <code>_</code>.</dd><dt><a class="struct" href="struct.TypeMacro.html" title="struct syn::TypeMacro">Type<wbr>Macro</a></dt><dd>A macro in the type position.</dd><dt><a class="struct" href="struct.TypeNever.html" title="struct syn::TypeNever">Type<wbr>Never</a></dt><dd>The never type: <code>!</code>.</dd><dt><a class="struct" href="struct.TypeParam.html" title="struct syn::TypeParam">Type<wbr>Param</a></dt><dd>A generic type parameter: <code>T: Into<String></code>.</dd><dt><a class="struct" href="struct.TypeParen.html" title="struct syn::TypeParen">Type<wbr>Paren</a></dt><dd>A parenthesized type equivalent to the inner type.</dd><dt><a class="struct" href="struct.TypePath.html" title="struct syn::TypePath">Type<wbr>Path</a></dt><dd>A path like <code>std::slice::Iter</code>, optionally qualified with a
|
||
self-type as in <code><Vec<T> as SomeTrait>::Associated</code>.</dd><dt><a class="struct" href="struct.TypePtr.html" title="struct syn::TypePtr">TypePtr</a></dt><dd>A raw pointer type: <code>*const T</code> or <code>*mut T</code>.</dd><dt><a class="struct" href="struct.TypeReference.html" title="struct syn::TypeReference">Type<wbr>Reference</a></dt><dd>A reference type: <code>&'a T</code> or <code>&'a mut T</code>.</dd><dt><a class="struct" href="struct.TypeSlice.html" title="struct syn::TypeSlice">Type<wbr>Slice</a></dt><dd>A dynamically sized slice type: <code>[T]</code>.</dd><dt><a class="struct" href="struct.TypeTraitObject.html" title="struct syn::TypeTraitObject">Type<wbr>Trait<wbr>Object</a></dt><dd>A trait object type <code>dyn Bound1 + Bound2 + Bound3</code> where <code>Bound</code> is a
|
||
trait or a lifetime.</dd><dt><a class="struct" href="struct.TypeTuple.html" title="struct syn::TypeTuple">Type<wbr>Tuple</a></dt><dd>A tuple type: <code>(A, B, C, String)</code>.</dd><dt><a class="struct" href="struct.Variant.html" title="struct syn::Variant">Variant</a></dt><dd>An enum variant.</dd><dt><a class="struct" href="struct.VisRestricted.html" title="struct syn::VisRestricted">VisRestricted</a></dt><dd>A visibility level restricted to some path: <code>pub(self)</code> or
|
||
<code>pub(super)</code> or <code>pub(crate)</code> or <code>pub(in some::module)</code>.</dd><dt><a class="struct" href="struct.WhereClause.html" title="struct syn::WhereClause">Where<wbr>Clause</a></dt><dd>A <code>where</code> clause in a definition: <code>where T: Deserialize<'de>, D: 'static</code>.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.AttrStyle.html" title="enum syn::AttrStyle">Attr<wbr>Style</a></dt><dd>Distinguishes between attributes that decorate an item and attributes
|
||
that are contained within an item.</dd><dt><a class="enum" href="enum.BinOp.html" title="enum syn::BinOp">BinOp</a></dt><dd>A binary operator: <code>+</code>, <code>+=</code>, <code>&</code>.</dd><dt><a class="enum" href="enum.Data.html" title="enum syn::Data">Data</a></dt><dd>The storage of a struct, enum or union data structure.</dd><dt><a class="enum" href="enum.Expr.html" title="enum syn::Expr">Expr</a></dt><dd>A Rust expression.</dd><dt><a class="enum" href="enum.FieldMutability.html" title="enum syn::FieldMutability">Field<wbr>Mutability</a></dt><dd>Unused, but reserved for RFC 3323 restrictions.</dd><dt><a class="enum" href="enum.Fields.html" title="enum syn::Fields">Fields</a></dt><dd>Data stored within an enum variant or struct.</dd><dt><a class="enum" href="enum.GenericArgument.html" title="enum syn::GenericArgument">Generic<wbr>Argument</a></dt><dd>An individual generic argument, like <code>'a</code>, <code>T</code>, or <code>Item = T</code>.</dd><dt><a class="enum" href="enum.GenericParam.html" title="enum syn::GenericParam">Generic<wbr>Param</a></dt><dd>A generic type parameter, lifetime, or const generic: <code>T: Into<String></code>,
|
||
<code>'a: 'b</code>, <code>const LEN: usize</code>.</dd><dt><a class="enum" href="enum.Lit.html" title="enum syn::Lit">Lit</a></dt><dd>A Rust literal such as a string or integer or boolean.</dd><dt><a class="enum" href="enum.MacroDelimiter.html" title="enum syn::MacroDelimiter">Macro<wbr>Delimiter</a></dt><dd>A grouping token that surrounds a macro body: <code>m!(...)</code> or <code>m!{...}</code> or <code>m![...]</code>.</dd><dt><a class="enum" href="enum.Member.html" title="enum syn::Member">Member</a></dt><dd>A struct or tuple struct field accessed in a struct literal or field
|
||
expression.</dd><dt><a class="enum" href="enum.Meta.html" title="enum syn::Meta">Meta</a></dt><dd>Content of a compile-time structured attribute.</dd><dt><a class="enum" href="enum.PathArguments.html" title="enum syn::PathArguments">Path<wbr>Arguments</a></dt><dd>Angle bracketed or parenthesized arguments of a path segment.</dd><dt><a class="enum" href="enum.ReturnType.html" title="enum syn::ReturnType">Return<wbr>Type</a></dt><dd>Return type of a function signature.</dd><dt><a class="enum" href="enum.TraitBoundModifier.html" title="enum syn::TraitBoundModifier">Trait<wbr>Bound<wbr>Modifier</a></dt><dd>A modifier on a trait bound, currently only used for the <code>?</code> in
|
||
<code>?Sized</code>.</dd><dt><a class="enum" href="enum.Type.html" title="enum syn::Type">Type</a></dt><dd>The possible types that a Rust value could have.</dd><dt><a class="enum" href="enum.TypeParamBound.html" title="enum syn::TypeParamBound">Type<wbr>Param<wbr>Bound</a></dt><dd>A trait or lifetime used as a bound on a type parameter.</dd><dt><a class="enum" href="enum.UnOp.html" title="enum syn::UnOp">UnOp</a></dt><dd>A unary operator: <code>*</code>, <code>!</code>, <code>-</code>.</dd><dt><a class="enum" href="enum.Visibility.html" title="enum syn::Visibility">Visibility</a></dt><dd>The visibility level of an item: inherited or <code>pub</code> or
|
||
<code>pub(restricted)</code>.</dd><dt><a class="enum" href="enum.WherePredicate.html" title="enum syn::WherePredicate">Where<wbr>Predicate</a></dt><dd>A single predicate in a <code>where</code> clause: <code>T: Deserialize<'de></code>.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.parse.html" title="fn syn::parse">parse</a></dt><dd>Parse tokens of source code into the chosen syntax tree node.</dd><dt><a class="fn" href="fn.parse2.html" title="fn syn::parse2">parse2</a></dt><dd>Parse a proc-macro2 token stream into the chosen syntax tree node.</dd><dt><a class="fn" href="fn.parse_str.html" title="fn syn::parse_str">parse_<wbr>str</a></dt><dd>Parse a string of Rust code into the chosen syntax tree node.</dd></dl><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><dl class="item-table"><dt><a class="type" href="type.Result.html" title="type syn::Result">Result</a></dt><dd>The result of a Syn parser.</dd></dl></section></div></main></body></html> |