Add the opensmtpd_derive crate
This commit is contained in:
parent
d1d51bbaa8
commit
4598fb33e4
29 changed files with 81 additions and 39 deletions
20
opensmtpd-derive/Cargo.toml
Normal file
20
opensmtpd-derive/Cargo.toml
Normal file
|
@ -0,0 +1,20 @@
|
|||
[package]
|
||||
name = "opensmtpd_derive"
|
||||
version = "0.3.0"
|
||||
authors = ["Rodolphe Bréard <rodolphe@what.tf>"]
|
||||
edition = "2018"
|
||||
description = "Interface for OpenSMTPD filters"
|
||||
keywords = ["opensmtpd", "filter", "mail"]
|
||||
documentation = "https://docs.rs/opensmtpd-derive/"
|
||||
repository = "https://github.com/breard-r/rust-opensmtpd"
|
||||
readme = "README.md"
|
||||
license = "MIT OR Apache-2.0"
|
||||
include = ["src/**/*", "Cargo.toml", "../LICENSE-*.txt"]
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "1.0"
|
||||
quote = "1.0"
|
||||
syn = { version = "1.0", features = ["full", "extra-traits"] }
|
18
opensmtpd-derive/src/lib.rs
Normal file
18
opensmtpd-derive/src/lib.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use proc_macro::TokenStream;
|
||||
use proc_macro2::Span;
|
||||
use quote::quote;
|
||||
use syn::{parse_macro_input, Ident, ItemFn};
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn register(_attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let item = parse_macro_input!(input as ItemFn);
|
||||
let fn_name = item.sig.ident.to_string().replacen("on_", "has_", 1);
|
||||
let fn_name = Ident::new(&fn_name, Span::call_site());
|
||||
let output = quote! {
|
||||
fn #fn_name(&self) -> bool {
|
||||
true
|
||||
}
|
||||
#item
|
||||
};
|
||||
output.into()
|
||||
}
|
Reference in a new issue