2024-03-23 02:22:52 +00:00
|
|
|
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
|
|
|
|
2024-02-19 17:09:47 +00:00
|
|
|
//! Derive implementations for `bevy_gizmos`.
|
|
|
|
|
2024-01-18 15:52:50 +00:00
|
|
|
use bevy_macro_utils::BevyManifest;
|
|
|
|
use proc_macro::TokenStream;
|
|
|
|
use quote::quote;
|
|
|
|
use syn::{parse_macro_input, parse_quote, DeriveInput, Path};
|
|
|
|
|
2024-02-19 17:09:47 +00:00
|
|
|
/// Implements the [`GizmoConfigGroup`] trait for a gizmo config group type.
|
2024-01-18 15:52:50 +00:00
|
|
|
#[proc_macro_derive(GizmoConfigGroup)]
|
|
|
|
pub fn derive_gizmo_config_group(input: TokenStream) -> TokenStream {
|
|
|
|
let mut ast = parse_macro_input!(input as DeriveInput);
|
|
|
|
let bevy_gizmos_path: Path = BevyManifest::default().get_path("bevy_gizmos");
|
|
|
|
let bevy_reflect_path: Path = BevyManifest::default().get_path("bevy_reflect");
|
|
|
|
|
|
|
|
ast.generics.make_where_clause().predicates.push(
|
|
|
|
parse_quote! { Self: #bevy_reflect_path::Reflect + #bevy_reflect_path::TypePath + Default},
|
|
|
|
);
|
|
|
|
|
|
|
|
let struct_name = &ast.ident;
|
|
|
|
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
|
|
|
|
|
|
|
|
TokenStream::from(quote! {
|
|
|
|
impl #impl_generics #bevy_gizmos_path::config::GizmoConfigGroup for #struct_name #type_generics #where_clause {
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|