derive_into_element.rs

 1use proc_macro::TokenStream;
 2use quote::quote;
 3use syn::{DeriveInput, parse_macro_input};
 4
 5pub fn derive_into_element(input: TokenStream) -> TokenStream {
 6    let ast = parse_macro_input!(input as DeriveInput);
 7    let type_name = &ast.ident;
 8    let (impl_generics, type_generics, where_clause) = ast.generics.split_for_impl();
 9
10    let r#gen = quote! {
11        impl #impl_generics gpui::IntoElement for #type_name #type_generics
12        #where_clause
13        {
14            type Element = gpui::Component<Self>;
15
16            #[track_caller]
17            fn into_element(self) -> Self::Element {
18                gpui::Component::new(self)
19            }
20        }
21    };
22
23    r#gen.into()
24}