1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
extern crate proc_macro;
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};
#[proc_macro_derive(BackendContext)]
pub fn derive_backend_context(input: TokenStream) -> TokenStream {
let input: DeriveInput = parse_macro_input!(input);
let ident = &input.ident;
let output = quote! {
impl email::backend::BackendContext for #ident {}
};
TokenStream::from(output)
}
// TODO
// #[proc_macro_derive(EmailBackendContext, attributes(context))]
// pub fn derive_email_backend_context(input: TokenStream) -> TokenStream {
// use proc_macro::TokenStream;
// use quote::quote;
// use syn::{parse_macro_input, Attribute, Data, DataStruct, DeriveInput, Fields, Meta, PathSegment};
// let input: DeriveInput = parse_macro_input!(input);
// let mut output = quote!();
// match input.data {
// Data::Struct(DataStruct {
// fields: Fields::Named(ref fields),
// ..
// }) => {
// for field in &fields.named {
// if let Some(_ident) = &field.ident {
// for attr in &field.attrs {
// if let Attribute {
// meta: Meta::Path(path),
// ..
// } = attr
// {
// for segment in &path.segments {
// match segment {
// PathSegment { ident, .. } if ident.to_string() == "context" => {
// output = quote! {
// #output
// impl BackendContextMapper<ImapContextSync> for MyStaticContext {
// fn map_context(&self) -> Option<&ImapContextSync> {
// Some(&self.imap)
// }
// }
// }
// }
// _ => (),
// }
// }
// };
// }
// }
// }
// }
// _ => (),
// };
// TokenStream::from(output)
// }