2024-03-02 09:26:34 +00:00
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "utf-8" > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" > < meta name = "generator" content = "rustdoc" > < meta name = "description" content = "Tokens representing Rust punctuation, keywords, and delimiters." > < title > syn::token - Rust< / title > < link rel = "preload" as = "font" type = "font/woff2" crossorigin href = "../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2" > < link rel = "preload" as = "font" type = "font/woff2" crossorigin href = "../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2" > < link rel = "preload" as = "font" type = "font/woff2" crossorigin href = "../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2" > < link rel = "preload" as = "font" type = "font/woff2" crossorigin href = "../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2" > < link rel = "preload" as = "font" type = "font/woff2" crossorigin href = "../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2" > < link rel = "stylesheet" href = "../../static.files/normalize-76eba96aa4d2e634.css" > < link rel = "stylesheet" href = "../../static.files/rustdoc-ac92e1bbe349e143.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.76.0 (07dca489a 2024-02-04)" data-channel = "1.76.0" data-search-js = "search-2b6ce74ff89ae146.js" data-settings-js = "settings-4313503d2e1961c2.js" > < script src = "../../static.files/storage-f2adc0d6ca4d09fb.js" > < / script > < script defer src = "../sidebar-items.js" > < / script > < script defer src = "../../static.files/main-305769736d49e732.js" > < / script > < noscript > < link rel = "stylesheet" href = "../../static.files/noscript-feafe1bb7466e4bd.css" > < / noscript > < link rel = "alternate icon" type = "image/png" href = "../../static.files/favicon-16x16-8b506e7a72182f1c.png" > < link rel = "alternate icon" type = "image/png" href = "../../static.files/favicon-32x32-422f7d1d52889060.png" > < link rel = "icon" type = "image/svg+xml" href = "../../static.files/favicon-2c020d218678b618.svg" > < / head > < body class = "rustdoc mod" > <!-- [if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif] --> < nav class = "mobile-topbar" > < button class = "sidebar-menu-toggle" > ☰ < / button > < / nav > < nav class = "sidebar" > < div class = "sidebar-crate" > < h2 > < a href = "../../syn/index.html" > syn< / a > < span class = "version" > 2.0.52< / span > < / h2 > < / div > < h2 class = "location" > < a href = "#" > Module token< / a > < / h2 > < div class = "sidebar-elems" > < section > < ul class = "block" > < li > < a href = "#structs" > Structs< / a > < / li > < li > < a href = "#traits" > Traits< / a > < / li > < / ul > < / section > < h2 > < a href = "../index.html" > In crate syn< / a > < / h2 > < / div > < / nav > < div class = "sidebar-resizer" > < / div >
2024-02-13 06:38:44 +00:00
< main > < div class = "width-limiter" > < nav class = "sub" > < form class = "search-form" > < span > < / span > < div id = "sidebar-button" tabindex = "-1" > < a href = "../../syn/all.html" title = "show sidebar" > < / a > < / div > < input class = "search-input" name = "search" aria-label = "Run search in the documentation" autocomplete = "off" spellcheck = "false" placeholder = "Click or press ‘ S’ to search, ‘ ?’ for more options…" type = "search" > < div id = "help-button" tabindex = "-1" > < a href = "../../help.html" title = "help" > ?< / a > < / div > < div id = "settings-menu" tabindex = "-1" > < a href = "../../settings.html" title = "settings" > < img width = "22" height = "22" alt = "Change settings" src = "../../static.files/wheel-7b819b6101059cd0.svg" > < / a > < / div > < / form > < / nav > < section id = "main-content" class = "content" > < div class = "main-heading" > < h1 > Module < a href = "../index.html" > syn< / a > ::< wbr > < a class = "mod" href = "#" > token< / a > < button id = "copy-path" title = "Copy item path to clipboard" > < img src = "../../static.files/clipboard-7571035ce49a181d.svg" width = "19" height = "18" alt = "Copy item path" > < / button > < / h1 > < span class = "out-of-band" > < a class = "src" href = "../../src/syn/token.rs.html#1-1138" > source< / a > · < button id = "toggle-all-docs" title = "collapse all docs" > [< span > − < / span > ]< / button > < / span > < / div > < details class = "toggle top-doc" open > < summary class = "hideme" > < span > Expand description< / span > < / summary > < div class = "docblock" > < p > Tokens representing Rust punctuation, keywords, and delimiters.< / p >
< p > The type names in this module can be difficult to keep straight, so we
prefer to use the < a href = "../macro.Token.html" title = "macro syn::Token" > < code > Token!< / code > < / a > macro instead. This is a type-macro that
expands to the token type of the given token.< / p >
< h2 id = "example" > < a href = "#example" > Example< / a > < / h2 >
< p > The < a href = "../struct.ItemStatic.html" title = "struct syn::ItemStatic" > < code > ItemStatic< / code > < / a > syntax tree node is defined like this.< / p >
< div class = "example-wrap" > < pre class = "rust rust-example-rendered" > < code > < span class = "kw" > pub struct < / span > ItemStatic {
< span class = "kw" > pub < / span > attrs: Vec< Attribute> ,
< span class = "kw" > pub < / span > vis: Visibility,
< span class = "kw" > pub < / span > static_token: < span class = "macro" > Token!< / span > [< span class = "kw" > static< / span > ],
< span class = "kw" > pub < / span > mutability: < span class = "prelude-ty" > Option< / span > < < span class = "macro" > Token!< / span > [< span class = "kw-2" > mut< / span > ]> ,
< span class = "kw" > pub < / span > ident: Ident,
< span class = "kw" > pub < / span > colon_token: < span class = "macro" > Token!< / span > [:],
< span class = "kw" > pub < / span > ty: Box< Type> ,
< span class = "kw" > pub < / span > eq_token: < span class = "macro" > Token!< / span > [=],
< span class = "kw" > pub < / span > expr: Box< Expr> ,
< span class = "kw" > pub < / span > semi_token: < span class = "macro" > Token!< / span > [;],
}< / code > < / pre > < / div >
< h2 id = "parsing" > < a href = "#parsing" > Parsing< / a > < / h2 >
< p > Keywords and punctuation can be parsed through the < a href = "../parse/struct.ParseBuffer.html#method.parse" title = "method syn::parse::ParseBuffer::parse" > < code > ParseStream::parse< / code > < / a >
method. Delimiter tokens are parsed using the < a href = "../macro.parenthesized.html" title = "macro syn::parenthesized" > < code > parenthesized!< / code > < / a > ,
< a href = "../macro.bracketed.html" title = "macro syn::bracketed" > < code > bracketed!< / code > < / a > and < a href = "../macro.braced.html" title = "macro syn::braced" > < code > braced!< / code > < / a > macros.< / p >
< div class = "example-wrap" > < pre class = "rust rust-example-rendered" > < code > < span class = "kw" > use < / span > syn::{Attribute, < span class = "prelude-ty" > Result< / span > };
< span class = "kw" > use < / span > syn::parse::{Parse, ParseStream};
< span class = "comment" > // Parse the ItemStatic struct shown above.
< / span > < span class = "kw" > impl < / span > Parse < span class = "kw" > for < / span > ItemStatic {
< span class = "kw" > fn < / span > parse(input: ParseStream) -> < span class = "prelude-ty" > Result< / span > < < span class = "self" > Self< / span > > {
< span class = "prelude-val" > Ok< / span > (ItemStatic {
attrs: input.call(Attribute::parse_outer)< span class = "question-mark" > ?< / span > ,
vis: input.parse()< span class = "question-mark" > ?< / span > ,
static_token: input.parse()< span class = "question-mark" > ?< / span > ,
mutability: input.parse()< span class = "question-mark" > ?< / span > ,
ident: input.parse()< span class = "question-mark" > ?< / span > ,
colon_token: input.parse()< span class = "question-mark" > ?< / span > ,
ty: input.parse()< span class = "question-mark" > ?< / span > ,
eq_token: input.parse()< span class = "question-mark" > ?< / span > ,
expr: input.parse()< span class = "question-mark" > ?< / span > ,
semi_token: input.parse()< span class = "question-mark" > ?< / span > ,
})
}
}< / code > < / pre > < / div >
< h2 id = "other-operations" > < a href = "#other-operations" > Other operations< / a > < / h2 >
< p > Every keyword and punctuation token supports the following operations.< / p >
< ul >
< li >
< p > < a href = "../parse/struct.ParseBuffer.html#method.peek" title = "method syn::parse::ParseBuffer::peek" > Peeking< / a > — < code > input.peek(Token![...])< / code > < / p >
< / li >
< li >
< p > < a href = "../parse/struct.ParseBuffer.html#method.parse" title = "method syn::parse::ParseBuffer::parse" > Parsing< / a > — < code > input.parse::< Token![...]> ()?< / code > < / p >
< / li >
< li >
< p > < a href = "https://docs.rs/quote/1.0/quote/trait.ToTokens.html" > Printing< / a > — < code > quote!( ... #the_token ... )< / code > < / p >
< / li >
< li >
< p > Construction from a < a href = "https://docs.rs/proc-macro2/1.0/proc_macro2/struct.Span.html" > < code > Span< / code > < / a > — < code > let the_token = Token![...](sp)< / code > < / p >
< / li >
< li >
< p > Field access to its span — < code > let sp = the_token.span< / code > < / p >
< / li >
< / ul >
< / div > < / details > < h2 id = "structs" class = "section-header" > < a href = "#structs" > Structs< / a > < / h2 > < ul class = "item-table" > < li > < div class = "item-name" > < a class = "struct" href = "struct.Abstract.html" title = "struct syn::token::Abstract" > Abstract< / a > < / div > < div class = "desc docblock-short" > < code > abstract< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.And.html" title = "struct syn::token::And" > And< / a > < / div > < div class = "desc docblock-short" > < code > & < / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.AndAnd.html" title = "struct syn::token::AndAnd" > AndAnd< / a > < / div > < div class = "desc docblock-short" > < code > & & < / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.AndEq.html" title = "struct syn::token::AndEq" > AndEq< / a > < / div > < div class = "desc docblock-short" > < code > & =< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.As.html" title = "struct syn::token::As" > As< / a > < / div > < div class = "desc docblock-short" > < code > as< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Async.html" title = "struct syn::token::Async" > Async< / a > < / div > < div class = "desc docblock-short" > < code > async< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.At.html" title = "struct syn::token::At" > At< / a > < / div > < div class = "desc docblock-short" > < code > @< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Auto.html" title = "struct syn::token::Auto" > Auto< / a > < / div > < div class = "desc docblock-short" > < code > auto< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Await.html" title = "struct syn::token::Await" > Await< / a > < / div > < div class = "desc docblock-short" > < code > await< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Become.html" title = "struct syn::token::Become" > Become< / a > < / div > < div class = "desc docblock-short" > < code > become< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Box.html" title = "struct syn::token::Box" > Box< / a > < / div > < div class = "desc docblock-short" > < code > box< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Brace.html" title = "struct syn::token::Brace" > Brace< / a > < / div > < div class = "desc docblock-short" > < code > {< / code > …< code > }< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Bracket.html" title = "struct syn::token::Bracket" > Bracket< / a > < / div > < div class = "desc docblock-short" > < code > [< / code > …< code > ]< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Break.html" title = "struct syn::token::Break" > Break< / a > < / div > < div class = "desc docblock-short" > < code > break< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Caret.html" title = "struct syn::token::Caret" > Caret< / a > < / div > < div class = "desc docblock-short" > < code > ^< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.CaretEq.html" title = "struct syn::token::CaretEq" > CaretEq< / a > < / div > < div class = "desc docblock-short" > < code > ^=< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Colon.html" title = "struct syn::token::Colon" > Colon< / a > < / div > < div class = "desc docblock-short" > < code > :< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Comma.html" title = "struct syn::token::Comma" > Comma< / a > < / div > < div class = "desc docblock-short" > < code > ,< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Const.html" title = "struct syn::token::Const" > Const< / a > < / div > < div class = "desc docblock-short" > < code > const< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Continue.html" title = "struct syn::token::Continue" > Continue< / a > < / div > < div class = "desc docblock-short" > < code > continue< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Crate.html" title = "struct syn::token::Crate" > Crate< / a > < / div > < div class = "desc docblock-short" > < code > crate< / code > < / div > < / li > < li > < div class = "item-name" > < a class = "struct" href = "struct.Default.html" title = "struct syn::token::Default" > Default< / a > < / div > < div class = "desc docblock-short" > < code > default< / code > < / div > <