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