This repository has been archived on 2023-09-20. You can view files and clone it, but cannot push or open issues or pull requests.
rust-opensmtpd/opensmtpd-derive/src/lib.rs
2021-02-28 13:56:40 +01:00

18 lines
483 B
Rust

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()
}