bevy_gizmos_macros/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! Derive implementations for `bevy_gizmos`.
4
5use bevy_macro_utils::BevyManifest;
6use proc_macro::TokenStream;
7use quote::quote;
8use syn::{parse_macro_input, parse_quote, DeriveInput, Path};
9
10/// Implements the [`GizmoConfigGroup`] trait for a gizmo config group type.
11#[proc_macro_derive(GizmoConfigGroup)]
12pub fn derive_gizmo_config_group(input: TokenStream) -> TokenStream {
13    let mut ast = parse_macro_input!(input as DeriveInput);
14    let bevy_gizmos_path: Path = BevyManifest::shared().get_path("bevy_gizmos");
15    let bevy_reflect_path: Path = BevyManifest::shared().get_path("bevy_reflect");
16
17    ast.generics.make_where_clause().predicates.push(
18        parse_quote! { Self: #bevy_reflect_path::Reflect + #bevy_reflect_path::TypePath + Default},
19    );
20
21    let struct_name = &ast.ident;
22    let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
23
24    TokenStream::from(quote! {
25        impl #impl_generics #bevy_gizmos_path::config::GizmoConfigGroup for #struct_name #type_generics #where_clause {
26        }
27    })
28}