You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
Rust
50 lines
1.5 KiB
Rust
use proc_macro::TokenStream;
|
|
use quote::quote;
|
|
use syn::{parse_macro_input, DeriveInput};
|
|
|
|
pub fn invoke(input: TokenStream) -> TokenStream {
|
|
let input = parse_macro_input!(input as DeriveInput);
|
|
let name = input.ident;
|
|
|
|
let expanded = quote! {
|
|
#[automatically_derived]
|
|
impl<B: crate::backend::Backend>
|
|
crate::view::NativeComponent<B> for #name
|
|
where
|
|
#name : crate::backend::Render<B>,
|
|
{}
|
|
|
|
#[automatically_derived]
|
|
impl<B: crate::backend::Backend>
|
|
crate::view::Construct<B> for #name
|
|
where
|
|
#name : crate::backend::Render<B>,
|
|
{
|
|
type Params = <Self as crate::view::NewNative<B>>::Params;
|
|
|
|
fn construct(params: Self::Params) -> Self {
|
|
<Self as crate::view::NewNative<B>>::new(params)
|
|
}
|
|
|
|
fn into_view(self) -> crate::view::SomeView<B> {
|
|
crate::view::SomeView::<B>::Native(Box::new(self))
|
|
}
|
|
}
|
|
|
|
#[automatically_derived]
|
|
impl<B: crate::backend::Backend>
|
|
crate::view::ConstructGroup<B> for #name
|
|
where
|
|
#name : crate::view::NewNativeGroup<B> + crate::view::Render<B>,
|
|
{
|
|
fn construct_group<'a, I>(params: Self::Params, children: I) -> Self
|
|
where
|
|
I: Iterator<Item = &'a View<B>>,
|
|
{
|
|
<Self as crate::view::NewNativeGroup<B>>::new_group(params, children)
|
|
}
|
|
}
|
|
};
|
|
expanded.into()
|
|
}
|