2023-11-19 03:05:47 +00:00
|
|
|
use proc_macro::TokenStream;
|
|
|
|
use quote::quote;
|
2023-11-20 19:55:27 +00:00
|
|
|
use syn::{parse_macro_input, DeriveInput};
|
2023-11-19 03:05:47 +00:00
|
|
|
|
2023-11-22 18:19:43 +00:00
|
|
|
pub fn derive_into_element(input: TokenStream) -> TokenStream {
|
2023-11-19 03:05:47 +00:00
|
|
|
let ast = parse_macro_input!(input as DeriveInput);
|
|
|
|
let type_name = &ast.ident;
|
2023-11-20 19:55:27 +00:00
|
|
|
let (impl_generics, type_generics, where_clause) = ast.generics.split_for_impl();
|
2023-11-19 03:05:47 +00:00
|
|
|
|
|
|
|
let gen = quote! {
|
2023-11-22 18:19:43 +00:00
|
|
|
impl #impl_generics gpui::IntoElement for #type_name #type_generics
|
2023-11-19 03:05:47 +00:00
|
|
|
#where_clause
|
|
|
|
{
|
2023-11-22 18:19:43 +00:00
|
|
|
type Element = gpui::Component<Self>;
|
2023-11-19 03:05:47 +00:00
|
|
|
|
2023-11-22 18:19:43 +00:00
|
|
|
fn into_element(self) -> Self::Element {
|
|
|
|
gpui::Component::new(self)
|
2023-11-19 03:05:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
gen.into()
|
|
|
|
}
|