[−][src]Macro syn::option
Turn a failed parse into None
and a successful parse into Some
.
A failed parse consumes none of the input.
- Syntax:
option!(THING)
- Output:
Option<THING>
#[macro_use] extern crate syn; use syn::{Label, Block}; use syn::synom::Synom; /// Parses a Rust loop. Equivalent to syn::ExprLoop. /// /// Examples: /// loop { println!("y"); } /// 'x: loop { break 'x; } struct ExprLoop { label: Option<Label>, loop_token: Token![loop], body: Block, } impl Synom for ExprLoop { named!(parse -> Self, do_parse!( // Loop may or may not have a label. label: option!(syn!(Label)) >> loop_token: keyword!(loop) >> body: syn!(Block) >> (ExprLoop { label, loop_token, body, }) )); }
This macro is available if Syn is built with the "parsing"
feature.