| 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 { | 
|---|
| 14 | pub fn new(transformer: Ident, function: Path) -> Self { | 
|---|
| 15 | Self { | 
|---|
| 16 | transformer, | 
|---|
| 17 | function, | 
|---|
| 18 | } | 
|---|
| 19 | } | 
|---|
| 20 | } | 
|---|
| 21 |  | 
|---|
| 22 | impl ToTokens for PostfixTransform { | 
|---|
| 23 | fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { | 
|---|
| 24 | let Self { | 
|---|
| 25 | transformer: &Ident, | 
|---|
| 26 | function: &Path, | 
|---|
| 27 | } = self; | 
|---|
| 28 | tokens.append_all(iter:quote!(.#transformer(#function))) | 
|---|
| 29 | } | 
|---|
| 30 | } | 
|---|
| 31 |  | 
|---|