Files
continuwuity/src/macros/implement.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

27 lines
452 B
Rust
Raw Normal View History

2024-07-26 06:41:26 +00:00
use proc_macro::TokenStream;
2024-07-26 20:40:07 +00:00
use quote::quote;
use syn::{ItemFn, Meta, MetaList};
2024-07-26 06:41:26 +00:00
2024-07-26 20:40:07 +00:00
use crate::Result;
2024-07-26 06:41:26 +00:00
2024-07-26 20:40:07 +00:00
pub(super) fn implement(item: ItemFn, args: &[Meta]) -> Result<TokenStream> {
let Meta::List(MetaList {
path,
..
}) = &args
2024-07-26 06:41:26 +00:00
.first()
.expect("missing path to trait or item to implement")
else {
panic!("invalid path to item for implement");
};
2024-07-26 20:40:07 +00:00
let input = item;
2024-07-26 06:41:26 +00:00
let out = quote! {
2024-07-26 20:40:07 +00:00
impl #path {
#input
2024-07-26 06:41:26 +00:00
}
};
2024-07-26 20:40:07 +00:00
Ok(out.into())
2024-07-26 06:41:26 +00:00
}