Function synstructure::match_pattern
[−]
[src]
pub fn match_pattern<'a, N: ToTokens>(name: &N, vd: &'a mut VariantData, bind: BindStyle) -> (Tokens, Vec<BindingInfo<'a>>)
Generate a match pattern for binding to the given VariantData This function
returns a tuple of the tokens which make up that match pattern, and a
BindingInfo
object for each of the bindings which were made. The bind
parameter controls the type of binding which is made.
The BindingInfo
object holds a mutable reference into the original
VariantData
, which means that mutations will be reflected in the source
object. This can be useful for removing attributes as they are used.
Example
extern crate syn; extern crate synstructure; use synstructure::{match_pattern, BindStyle}; fn main() { let mut ast = syn::parse_macro_input("struct A { a: i32, b: i32 }").unwrap(); let vd = if let syn::Body::Struct(ref mut vd) = ast.body { vd } else { unreachable!() }; let (tokens, bindings) = match_pattern(&ast.ident, vd, BindStyle::Ref); assert_eq!(&tokens.to_string(), "A { a : ref __binding_0 , b : ref __binding_1 , } "); assert_eq!(bindings.len(), 2); assert_eq!(&bindings[0].ident.to_string(), "__binding_0"); assert_eq!(&bindings[1].ident.to_string(), "__binding_1"); }Run