add macro for out-of-line definitions
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
96f6a75bc8
commit
3b5607ecdc
2 changed files with 27 additions and 0 deletions
23
src/macros/implement.rs
Normal file
23
src/macros/implement.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use proc_macro::TokenStream;
|
||||
use quote::{quote, ToTokens};
|
||||
use syn::{parse_macro_input, AttributeArgs, ItemFn, Meta, NestedMeta};
|
||||
|
||||
pub(super) fn implement(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let args = parse_macro_input!(args as AttributeArgs);
|
||||
let item = parse_macro_input!(input as ItemFn);
|
||||
|
||||
let NestedMeta::Meta(Meta::Path(receiver)) = args
|
||||
.first()
|
||||
.expect("missing path to trait or item to implement")
|
||||
else {
|
||||
panic!("invalid path to item for implement");
|
||||
};
|
||||
|
||||
let out = quote! {
|
||||
impl #receiver {
|
||||
#item
|
||||
}
|
||||
};
|
||||
|
||||
out.into_token_stream().into()
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
mod admin;
|
||||
mod cargo;
|
||||
mod debug;
|
||||
mod implement;
|
||||
mod refutable;
|
||||
mod rustc;
|
||||
mod utils;
|
||||
|
@ -23,3 +24,6 @@ pub fn rustc_flags_capture(args: TokenStream) -> TokenStream { rustc::flags_capt
|
|||
|
||||
#[proc_macro_attribute]
|
||||
pub fn refutable(args: TokenStream, input: TokenStream) -> TokenStream { refutable::refutable(args, input) }
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn implement(args: TokenStream, input: TokenStream) -> TokenStream { implement::implement(args, input) }
|
||||
|
|
Loading…
Add table
Reference in a new issue