1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};

pub fn derive_render_once(input: TokenStream) -> TokenStream {
    let ast = parse_macro_input!(input as DeriveInput);
    let type_name = &ast.ident;
    let (impl_generics, type_generics, where_clause) = ast.generics.split_for_impl();

    let gen = quote! {
        impl #impl_generics gpui::RenderOnce for #type_name #type_generics
        #where_clause
        {
            type Element = gpui::CompositeElement<Self>;

            fn element_id(&self) -> Option<ElementId> {
                None
            }

            fn render_once(self) -> Self::Element {
                gpui::CompositeElement::new(self)
            }
        }
    };

    gen.into()
}