David Tolnay | ad2836d | 2017-04-20 10:11:43 -0700 | [diff] [blame] | 1 | #![doc(html_root_url = "https://dtolnay.github.io/syn")] |
| 2 | |
David Tolnay | 02a8d47 | 2017-02-19 12:59:44 -0800 | [diff] [blame] | 3 | #![cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))] |
David Tolnay | aed77b0 | 2016-09-23 20:50:31 -0700 | [diff] [blame] | 4 | |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 5 | extern crate proc_macro; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 6 | extern crate proc_macro2; |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 7 | extern crate unicode_xid; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 8 | |
Nika Layzell | 7f5fc68 | 2017-10-25 00:47:10 -0400 | [diff] [blame] | 9 | #[cfg(any(feature = "printing", feature = "parsing"))] |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 10 | extern crate quote; |
| 11 | |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 12 | #[cfg_attr(feature = "parsing", macro_use)] |
David Tolnay | 5fe14fc | 2017-01-27 16:22:08 -0800 | [diff] [blame] | 13 | extern crate synom; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 14 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 15 | #[macro_use] |
| 16 | mod macros; |
| 17 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 18 | mod attr; |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 19 | pub use attr::{Attribute, AttrStyle, MetaItem, NestedMetaItem, MetaItemList, |
| 20 | MetaNameValue}; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 21 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 22 | mod data; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 23 | pub use data::{Field, Variant, VariantData, Visibility, VisRestricted, VisCrate, |
| 24 | VisPublic, VisInherited}; |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 25 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 26 | mod expr; |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 27 | pub use expr::{Expr, ExprKind, ExprBox, ExprInPlace, ExprArray, ExprCall, |
| 28 | ExprMethodCall, ExprTup, ExprBinary, ExprUnary, ExprCast, |
| 29 | ExprType, ExprIf, ExprIfLet, ExprWhile, ExprWhileLet, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 30 | ExprForLoop, ExprLoop, ExprMatch, ExprClosure, ExprBlock, |
| 31 | ExprAssign, ExprAssignOp, ExprField, ExprTupField, ExprIndex, |
| 32 | ExprRange, ExprPath, ExprAddrOf, ExprBreak, ExprContinue, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 33 | ExprRet, ExprStruct, ExprRepeat, ExprParen, ExprTry, ExprCatch, |
Nika Layzell | 42bf7e3 | 2017-10-24 23:10:16 -0400 | [diff] [blame] | 34 | ExprGroup, ExprYield}; |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 35 | |
| 36 | #[cfg(feature = "full")] |
| 37 | pub use expr::{Arm, BindingMode, Block, CaptureBy, FieldPat, FieldValue, Local, |
| 38 | MacStmtStyle, Pat, RangeLimits, Stmt, PatIdent, PatWild, |
| 39 | PatStruct, PatTuple, PatTupleStruct, PatPath, PatBox, PatRef, |
| 40 | PatLit, PatRange, PatSlice, InPlaceKind}; |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 41 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 42 | mod generics; |
David Tolnay | 63e3dee | 2017-06-03 20:13:17 -0700 | [diff] [blame] | 43 | pub use generics::{Generics, LifetimeDef, TraitBoundModifier, TyParam, TyParamBound, |
David Tolnay | fa23f57 | 2017-01-23 00:19:11 -0800 | [diff] [blame] | 44 | WhereBoundPredicate, WhereClause, WhereEqPredicate, WherePredicate, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 45 | WhereRegionPredicate, BoundLifetimes}; |
David Tolnay | e767892 | 2016-10-13 20:44:03 -0700 | [diff] [blame] | 46 | #[cfg(feature = "printing")] |
David Tolnay | c879a50 | 2017-01-25 15:51:32 -0800 | [diff] [blame] | 47 | pub use generics::{ImplGenerics, Turbofish, TyGenerics}; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 48 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 49 | mod ident; |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 50 | pub use ident::Ident; |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 51 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 52 | #[cfg(feature = "full")] |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 53 | mod item; |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 54 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 55 | pub use item::{Constness, Defaultness, FnArg, FnDecl, ForeignItemKind, ForeignItem, ItemForeignMod, |
David Tolnay | c1fea50 | 2016-10-30 17:54:02 -0700 | [diff] [blame] | 56 | ImplItem, ImplItemKind, ImplPolarity, Item, ItemKind, MethodSig, PathListItem, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 57 | TraitItem, TraitItemKind, ViewPath, ItemExternCrate, ItemUse, |
| 58 | ItemStatic, ItemConst, ItemFn, ItemMod, ItemTy, ItemEnum, |
| 59 | ItemStruct, ItemUnion, ItemTrait, ItemDefaultImpl, ItemImpl, |
| 60 | PathSimple, PathGlob, PathList, ForeignItemFn, ForeignItemStatic, |
| 61 | TraitItemConst, TraitItemMethod, TraitItemType, |
| 62 | ImplItemConst, ImplItemMethod, ImplItemType, ArgSelfRef, |
| 63 | ArgSelf, ArgCaptured}; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 64 | |
David Tolnay | 631cb8c | 2016-11-10 17:16:41 -0800 | [diff] [blame] | 65 | #[cfg(feature = "full")] |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 66 | mod file; |
David Tolnay | 631cb8c | 2016-11-10 17:16:41 -0800 | [diff] [blame] | 67 | #[cfg(feature = "full")] |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 68 | pub use file::File; |
David Tolnay | 631cb8c | 2016-11-10 17:16:41 -0800 | [diff] [blame] | 69 | |
David Tolnay | 63e3dee | 2017-06-03 20:13:17 -0700 | [diff] [blame] | 70 | mod lifetime; |
| 71 | pub use lifetime::Lifetime; |
| 72 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 73 | mod lit; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 74 | pub use lit::{Lit, LitKind}; |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 75 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 76 | mod mac; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 77 | pub use mac::{Mac, TokenTree}; |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 78 | |
David Tolnay | 0e83740 | 2016-12-22 17:25:55 -0500 | [diff] [blame] | 79 | mod derive; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 80 | pub use derive::{Body, DeriveInput, BodyEnum, BodyStruct}; |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 81 | |
David Tolnay | 3cb23a9 | 2016-10-07 23:02:21 -0700 | [diff] [blame] | 82 | mod op; |
| 83 | pub use op::{BinOp, UnOp}; |
| 84 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 85 | mod ty; |
Nika Layzell | 42bf7e3 | 2017-10-24 23:10:16 -0400 | [diff] [blame] | 86 | pub use ty::{Abi, AbiKind, AngleBracketedParameterData, BareFnArg, BareFnArgName, BareFnTy, |
| 87 | FunctionRetTy, MutTy, Mutability, ParenthesizedParameterData, Path, |
| 88 | PathParameters, PathSegment, PolyTraitRef, QSelf, Ty, TypeBinding, Unsafety, |
| 89 | TySlice, TyArray, TyPtr, TyRptr, TyBareFn, TyNever, TyTup, TyPath, |
| 90 | TyTraitObject, TyImplTrait, TyParen, TyInfer, TyGroup}; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 91 | #[cfg(feature = "printing")] |
| 92 | pub use ty::PathTokens; |
| 93 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 94 | pub use synom::span::Span; |
| 95 | pub use synom::tokens; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 96 | pub use synom::delimited; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 97 | |
Nika Layzell | a6f46c4 | 2017-10-26 15:26:16 -0400 | [diff] [blame^] | 98 | mod gen { |
| 99 | #[cfg(feature = "visit")] |
| 100 | pub mod visit; |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 101 | |
Nika Layzell | a6f46c4 | 2017-10-26 15:26:16 -0400 | [diff] [blame^] | 102 | #[cfg(feature = "visit_mut")] |
| 103 | pub mod visit_mut; |
Nika Layzell | 2772666 | 2017-10-24 23:16:35 -0400 | [diff] [blame] | 104 | |
Nika Layzell | a6f46c4 | 2017-10-26 15:26:16 -0400 | [diff] [blame^] | 105 | #[cfg(feature = "fold")] |
| 106 | pub mod fold; |
| 107 | } |
| 108 | pub use gen::*; |
gnzlbg | 9ae88d8 | 2017-01-26 20:45:17 +0100 | [diff] [blame] | 109 | |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 110 | //////////////////////////////////////////////////////////////////////////////// |
| 111 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 112 | #[cfg(feature = "parsing")] |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 113 | pub use synom::ParseError; |
Ted Driggs | 054abbb | 2017-05-01 12:20:52 -0700 | [diff] [blame] | 114 | |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 115 | #[cfg(feature = "parsing")] |
| 116 | use synom::{Synom, SynomBuffer}; |
Michael Layzell | 416724e | 2017-05-24 21:12:34 -0400 | [diff] [blame] | 117 | |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 118 | /// Parse tokens of source code into the chosen syn data type. |
| 119 | /// |
| 120 | /// This is preferred over parsing a string because tokens are able to preserve |
| 121 | /// information about where in the user's code they were originally written (the |
| 122 | /// "span" of the token), possibly allowing the compiler to produce better error |
| 123 | /// messages. |
| 124 | /// |
| 125 | /// # Examples |
| 126 | /// |
| 127 | /// ```rust,ignore |
| 128 | /// extern crate proc_macro; |
| 129 | /// use proc_macro::TokenStream; |
| 130 | /// |
| 131 | /// extern crate syn; |
| 132 | /// |
| 133 | /// #[macro_use] |
| 134 | /// extern crate quote; |
| 135 | /// |
| 136 | /// use syn::DeriveInput; |
| 137 | /// |
| 138 | /// #[proc_macro_derive(MyMacro)] |
| 139 | /// pub fn my_macro(input: TokenStream) -> TokenStream { |
| 140 | /// // Parse the tokens into a syntax tree |
| 141 | /// let ast: DeriveInput = syn::parse(input).unwrap(); |
| 142 | /// |
| 143 | /// // Build the output, possibly using quasi-quotation |
| 144 | /// let expanded = quote! { |
| 145 | /// /* ... */ |
| 146 | /// }; |
| 147 | /// |
| 148 | /// // Parse back to a token stream and return it |
| 149 | /// expanded.parse().unwrap() |
| 150 | /// } |
| 151 | /// ``` |
| 152 | #[cfg(feature = "parsing")] |
| 153 | pub fn parse<T>(tokens: proc_macro::TokenStream) -> Result<T, ParseError> |
| 154 | where T: Synom, |
| 155 | { |
| 156 | _parse(tokens.into()) |
| 157 | } |
| 158 | |
| 159 | #[cfg(feature = "parsing")] |
| 160 | fn _parse<T>(tokens: proc_macro2::TokenStream) -> Result<T, ParseError> |
| 161 | where T: Synom, |
| 162 | { |
| 163 | let buf = SynomBuffer::new(tokens); |
| 164 | let result = T::parse(buf.begin()); |
| 165 | let err = match result { |
| 166 | Ok((rest, t)) => { |
| 167 | if rest.eof() { |
| 168 | return Ok(t); |
| 169 | } else if rest == buf.begin() { |
| 170 | // parsed nothing |
| 171 | ParseError::new("failed to parse anything") |
| 172 | } else { |
| 173 | ParseError::new("failed to parse all tokens") |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 174 | } |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 175 | } |
| 176 | Err(err) => err, |
| 177 | }; |
| 178 | match T::description() { |
Alex Crichton | c1b76f5 | 2017-07-06 15:04:24 -0700 | [diff] [blame] | 179 | Some(s) => Err(ParseError::new(format!("failed to parse {}: {}", s, err))), |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 180 | None => Err(err), |
| 181 | } |
| 182 | } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 183 | |
Nika Layzell | cda7ebd | 2017-10-24 23:10:44 -0400 | [diff] [blame] | 184 | /// Parse a `quote::Tokens` of Rust code into the chosen syn data type. |
| 185 | /// |
| 186 | /// # Examples |
| 187 | /// |
| 188 | /// ```rust |
| 189 | /// extern crate syn; |
| 190 | /// # |
| 191 | /// # #[macro_use] |
| 192 | /// # extern crate error_chain; |
| 193 | /// # #[macro_use] |
| 194 | /// # extern crate quote; |
| 195 | /// |
| 196 | /// use syn::Expr; |
| 197 | /// # |
| 198 | /// # error_chain! { |
| 199 | /// # foreign_links { |
| 200 | /// # Syn(syn::ParseError); |
| 201 | /// # } |
| 202 | /// # } |
| 203 | /// |
| 204 | /// fn run() -> Result<()> { |
| 205 | /// let code = quote!(assert_eq!(u8::max_value(), 255)); |
| 206 | /// let expr = syn::parse_tokens::<Expr>(code)?; |
| 207 | /// println!("{:#?}", expr); |
| 208 | /// Ok(()) |
| 209 | /// } |
| 210 | /// # |
| 211 | /// # fn main() { run().unwrap() } |
| 212 | /// ``` |
| 213 | #[cfg(feature = "parsing")] |
| 214 | pub fn parse_tokens<T: Synom>(tokens: quote::Tokens) -> Result<T, ParseError> { |
| 215 | _parse(tokens.into()) |
| 216 | } |
| 217 | |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 218 | /// Parse a string of Rust code into the chosen syn data type. |
| 219 | /// |
| 220 | /// # Examples |
| 221 | /// |
| 222 | /// ```rust |
| 223 | /// extern crate syn; |
| 224 | /// # |
| 225 | /// # #[macro_use] |
| 226 | /// # extern crate error_chain; |
| 227 | /// |
| 228 | /// use syn::Expr; |
| 229 | /// # |
| 230 | /// # error_chain! { |
| 231 | /// # foreign_links { |
| 232 | /// # Syn(syn::ParseError); |
| 233 | /// # } |
| 234 | /// # } |
| 235 | /// |
| 236 | /// fn run() -> Result<()> { |
| 237 | /// let code = "assert_eq!(u8::max_value(), 255)"; |
| 238 | /// let expr = syn::parse_str::<Expr>(code)?; |
| 239 | /// println!("{:#?}", expr); |
| 240 | /// Ok(()) |
| 241 | /// } |
| 242 | /// # |
| 243 | /// # fn main() { run().unwrap() } |
| 244 | /// ``` |
| 245 | #[cfg(feature = "parsing")] |
| 246 | pub fn parse_str<T: Synom>(s: &str) -> Result<T, ParseError> { |
| 247 | _parse(s.parse()?) |
| 248 | } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 249 | |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 250 | // FIXME the name parse_file makes it sound like you might pass in a path to a |
| 251 | // file, rather than the content. |
| 252 | /// Parse the content of a file of Rust code. |
| 253 | /// |
| 254 | /// This is different from `syn::parse_str::<File>(content)` in two ways: |
| 255 | /// |
| 256 | /// - It discards a leading byte order mark `\u{FEFF}` if the file has one. |
| 257 | /// - It preserves the shebang line of the file, such as `#!/usr/bin/env rustx`. |
| 258 | /// |
| 259 | /// If present, either of these would be an error using `from_str`. |
| 260 | /// |
| 261 | /// # Examples |
| 262 | /// |
| 263 | /// ```rust,no_run |
| 264 | /// extern crate syn; |
| 265 | /// # |
| 266 | /// # #[macro_use] |
| 267 | /// # extern crate error_chain; |
| 268 | /// |
| 269 | /// use std::fs::File; |
| 270 | /// use std::io::Read; |
| 271 | /// # |
| 272 | /// # error_chain! { |
| 273 | /// # foreign_links { |
| 274 | /// # Io(std::io::Error); |
| 275 | /// # Syn(syn::ParseError); |
| 276 | /// # } |
| 277 | /// # } |
| 278 | /// |
| 279 | /// fn run() -> Result<()> { |
| 280 | /// let mut file = File::open("path/to/code.rs")?; |
| 281 | /// let mut content = String::new(); |
| 282 | /// file.read_to_string(&mut content)?; |
| 283 | /// |
| 284 | /// let ast = syn::parse_file(&content)?; |
| 285 | /// if let Some(shebang) = ast.shebang { |
| 286 | /// println!("{}", shebang); |
| 287 | /// } |
| 288 | /// println!("{} items", ast.items.len()); |
| 289 | /// |
| 290 | /// Ok(()) |
| 291 | /// } |
| 292 | /// # |
| 293 | /// # fn main() { run().unwrap() } |
| 294 | /// ``` |
| 295 | #[cfg(all(feature = "parsing", feature = "full"))] |
| 296 | pub fn parse_file(mut content: &str) -> Result<File, ParseError> { |
| 297 | // Strip the BOM if it is present |
| 298 | const BOM: &'static str = "\u{feff}"; |
| 299 | if content.starts_with(BOM) { |
| 300 | content = &content[BOM.len()..]; |
David Tolnay | 35161ff | 2016-09-03 11:33:15 -0700 | [diff] [blame] | 301 | } |
Michael Layzell | 5e107ff | 2017-01-24 19:58:39 -0500 | [diff] [blame] | 302 | |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 303 | let mut shebang = None; |
| 304 | if content.starts_with("#!") && !content.starts_with("#![") { |
| 305 | if let Some(idx) = content.find('\n') { |
| 306 | shebang = Some(content[..idx].to_string()); |
| 307 | content = &content[idx..]; |
| 308 | } else { |
| 309 | shebang = Some(content.to_string()); |
| 310 | content = ""; |
| 311 | } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 312 | } |
David Tolnay | 0a8972b | 2017-02-27 02:10:01 -0800 | [diff] [blame] | 313 | |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 314 | let mut file: File = parse_str(content)?; |
| 315 | file.shebang = shebang; |
| 316 | Ok(file) |
Michael Layzell | 5e107ff | 2017-01-24 19:58:39 -0500 | [diff] [blame] | 317 | } |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 318 | |
| 319 | #[cfg(feature = "printing")] |
| 320 | struct TokensOrDefault<'a, T: 'a>(&'a Option<T>); |
| 321 | |
| 322 | #[cfg(feature = "printing")] |
| 323 | impl<'a, T> quote::ToTokens for TokensOrDefault<'a, T> |
| 324 | where T: quote::ToTokens + Default, |
| 325 | { |
| 326 | fn to_tokens(&self, tokens: &mut quote::Tokens) { |
| 327 | match *self.0 { |
| 328 | Some(ref t) => t.to_tokens(tokens), |
| 329 | None => T::default().to_tokens(tokens), |
| 330 | } |
| 331 | } |
| 332 | } |