FINALLY transition events to global; slow text sending bug tho
This commit is contained in:
@@ -2,12 +2,13 @@ extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{
|
||||
Block, Ident, Signature, Token, Visibility,
|
||||
Attribute, Block, Ident, ItemTrait, Signature, Token, Visibility,
|
||||
parse::{Parse, ParseStream, Result},
|
||||
parse_macro_input,
|
||||
parse_macro_input, parse_quote,
|
||||
};
|
||||
|
||||
struct Input {
|
||||
attrs: Vec<Attribute>,
|
||||
vis: Visibility,
|
||||
name: Ident,
|
||||
fns: Vec<InputFn>,
|
||||
@@ -20,6 +21,7 @@ struct InputFn {
|
||||
|
||||
impl Parse for Input {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
let attrs = input.call(Attribute::parse_outer)?;
|
||||
let vis = input.parse()?;
|
||||
input.parse::<Token![trait]>()?;
|
||||
let name = input.parse()?;
|
||||
@@ -33,27 +35,23 @@ impl Parse for Input {
|
||||
if !input.is_empty() {
|
||||
input.error("function expected");
|
||||
}
|
||||
Ok(Input { vis, name, fns })
|
||||
Ok(Input {
|
||||
attrs,
|
||||
vis,
|
||||
name,
|
||||
fns,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// pub trait $name<W: WidgetLike<Tag>, Tag> {
|
||||
// $(
|
||||
// fn $fn $(<$($T $(: $TT $(+ $TL)?)?,)*>)?($self $(, $arg: $ty)*) -> $ret;
|
||||
// )*
|
||||
// }
|
||||
//
|
||||
// impl<W: WidgetLike<Tag>, Tag> $name<W, Tag> for W {
|
||||
// $(
|
||||
// fn $fn $(<$($T $(: $TT $(+ $TL)?)?,)*>)?($self $(, $arg: $ty)*) -> $ret {
|
||||
// $code
|
||||
// }
|
||||
// )*
|
||||
// }
|
||||
|
||||
#[proc_macro]
|
||||
pub fn widget_trait(input: TokenStream) -> TokenStream {
|
||||
let Input { vis, name, fns } = parse_macro_input!(input as Input);
|
||||
let Input {
|
||||
attrs,
|
||||
vis,
|
||||
name,
|
||||
fns,
|
||||
} = parse_macro_input!(input as Input);
|
||||
|
||||
let sigs: Vec<_> = fns.iter().map(|f| f.sig.clone()).collect();
|
||||
let impls: Vec<_> = fns
|
||||
@@ -61,10 +59,16 @@ pub fn widget_trait(input: TokenStream) -> TokenStream {
|
||||
.map(|InputFn { sig, body }| quote! { #sig #body })
|
||||
.collect();
|
||||
|
||||
TokenStream::from(quote! {
|
||||
let mut trai: ItemTrait = parse_quote!(
|
||||
#vis trait #name<WL: WidgetLike<Tag>, Tag> {
|
||||
#(#sigs;)*
|
||||
}
|
||||
);
|
||||
|
||||
trai.attrs = attrs;
|
||||
|
||||
TokenStream::from(quote! {
|
||||
#trai
|
||||
|
||||
impl<WL: WidgetLike<Tag>, Tag> #name<WL, Tag> for WL {
|
||||
#(#impls)*
|
||||
|
||||
Reference in New Issue
Block a user