mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-11-30 04:40:47 +01:00
derive GameEvent parsing
This commit is contained in:
parent
ab5a061eb0
commit
f5957059d8
10 changed files with 116 additions and 121 deletions
|
|
@ -3,8 +3,10 @@
|
|||
extern crate proc_macro;
|
||||
|
||||
mod event;
|
||||
mod events;
|
||||
|
||||
use crate::event::Event;
|
||||
use crate::events::Events;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::ToTokens;
|
||||
use std::fmt::{Debug, Display};
|
||||
|
|
@ -12,12 +14,20 @@ use syn::{parse_macro_input, DeriveInput, Error, Result};
|
|||
|
||||
/// Derive the `Event` trait for a struct
|
||||
#[proc_macro_derive(Event, attributes(event))]
|
||||
pub fn derive_pod(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
pub fn derive_event(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let expanded = derive_trait::<Event>(parse_macro_input!(input as DeriveInput));
|
||||
|
||||
proc_macro::TokenStream::from(expanded)
|
||||
}
|
||||
|
||||
/// Derive the `Events` trait for a struct
|
||||
#[proc_macro_derive(Events, attributes())]
|
||||
pub fn derive_events(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let expanded = derive_trait::<Events>(parse_macro_input!(input as DeriveInput));
|
||||
|
||||
proc_macro::TokenStream::from(expanded)
|
||||
}
|
||||
|
||||
/// Basic wrapper for error handling
|
||||
fn derive_trait<Trait: Derivable>(input: DeriveInput) -> TokenStream {
|
||||
derive_trait_inner::<Trait>(input).unwrap_or_else(|err| err.into_compile_error())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue