[−][src]Macro syn::map
macro_rules! map { ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => { ... }; ($i:expr, $f:expr, $g:expr) => { ... }; }
Transform the result of a parser by applying a function or closure.
- Syntax:
map!(THING, FN)
- Output: the return type of function FN applied to THING
#[macro_use] extern crate syn; use syn::{Expr, ExprIf}; /// Extracts the branch condition of an `if`-expression. fn get_cond(if_: ExprIf) -> Expr { *if_.cond } /// Parses a full `if`-expression but returns the condition part only. /// /// Example: `if x > 0xFF { "big" } else { "small" }` /// The return would be the expression `x > 0xFF`. named!(if_condition -> Expr, map!(syn!(ExprIf), get_cond) ); /// Equivalent using a closure. named!(if_condition2 -> Expr, map!(syn!(ExprIf), |if_| *if_.cond) );
This macro is available if Syn is built with the "parsing"
feature.