2025-04-08 06:14:09 +00:00
|
|
|
mod pair_update;
|
|
|
|
mod single_update;
|
|
|
|
|
|
|
|
use pair_update::pair_update;
|
|
|
|
use single_update::single_update;
|
|
|
|
|
2025-03-04 17:29:45 +00:00
|
|
|
use proc_macro::TokenStream;
|
2025-04-08 06:14:09 +00:00
|
|
|
use quote::quote;
|
2025-03-04 17:29:45 +00:00
|
|
|
use syn::{
|
2025-04-04 15:32:27 +00:00
|
|
|
DeriveInput, Ident, LitInt, Result,
|
2025-03-04 17:29:45 +00:00
|
|
|
parse::{Parse, ParseStream},
|
|
|
|
parse_macro_input,
|
|
|
|
token::Comma,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InputInfo {
|
|
|
|
macro_ident: Ident,
|
|
|
|
start: usize,
|
|
|
|
end: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Parse for InputInfo {
|
|
|
|
fn parse(input: ParseStream) -> Result<Self> {
|
|
|
|
let macro_ident = input.parse::<Ident>()?;
|
|
|
|
input.parse::<Comma>()?;
|
|
|
|
let start = input.parse::<LitInt>()?.base10_parse()?;
|
|
|
|
input.parse::<Comma>()?;
|
|
|
|
let end = input.parse::<LitInt>()?.base10_parse()?;
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
macro_ident,
|
|
|
|
start,
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[proc_macro]
|
|
|
|
pub fn implement_pair_update(input: TokenStream) -> TokenStream {
|
|
|
|
let input = parse_macro_input!(input as InputInfo);
|
|
|
|
|
2025-04-08 06:14:09 +00:00
|
|
|
pair_update(input)
|
|
|
|
}
|
2025-03-04 17:29:45 +00:00
|
|
|
|
2025-04-08 06:14:09 +00:00
|
|
|
#[proc_macro]
|
|
|
|
pub fn implement_single_update(input: TokenStream) -> TokenStream {
|
|
|
|
let input = parse_macro_input!(input as InputInfo);
|
2025-03-04 17:29:45 +00:00
|
|
|
|
2025-04-08 06:14:09 +00:00
|
|
|
single_update(input)
|
2025-03-04 17:29:45 +00:00
|
|
|
}
|
2025-04-04 15:32:27 +00:00
|
|
|
|
|
|
|
#[proc_macro_derive(Resource)]
|
|
|
|
pub fn derive_resource(input: TokenStream) -> TokenStream {
|
|
|
|
let ast = parse_macro_input!(input as DeriveInput);
|
|
|
|
|
|
|
|
let implementor = ast.ident;
|
|
|
|
|
|
|
|
TokenStream::from(quote! {
|
2025-04-04 18:18:04 +00:00
|
|
|
impl ecs::resources::Resource for #implementor {}
|
2025-04-04 15:32:27 +00:00
|
|
|
})
|
|
|
|
}
|