• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use quote::{quote, ToTokens, TokenStreamExt};
2 use syn::{Ident, Path};
3 
4 /// A method invocation applied to a value.
5 ///
6 /// This is used for `map` and `and_then` transforms in derivations.
7 #[derive(Debug, Clone, PartialEq, Eq)]
8 pub struct PostfixTransform {
9     pub(crate) transformer: Ident,
10     pub(crate) function: Path,
11 }
12 
13 impl PostfixTransform {
new(transformer: Ident, function: Path) -> Self14     pub fn new(transformer: Ident, function: Path) -> Self {
15         Self {
16             transformer,
17             function,
18         }
19     }
20 }
21 
22 impl ToTokens for PostfixTransform {
to_tokens(&self, tokens: &mut proc_macro2::TokenStream)23     fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
24         let Self {
25             transformer,
26             function,
27         } = self;
28         tokens.append_all(quote!(.#transformer(#function)))
29     }
30 }
31