mirror of
https://github.com/bevyengine/bevy
synced 2024-12-28 05:53:07 +00:00
26 lines
1,011 B
Rust
26 lines
1,011 B
Rust
|
//! Contains code related specifically to Bevy's type registration.
|
||
|
|
||
|
use proc_macro2::Ident;
|
||
|
use quote::quote;
|
||
|
use syn::{Generics, Path};
|
||
|
|
||
|
/// Creates the `GetTypeRegistration` impl for the given type data.
|
||
|
pub(crate) fn impl_get_type_registration(
|
||
|
type_name: &Ident,
|
||
|
bevy_reflect_path: &Path,
|
||
|
registration_data: &[Ident],
|
||
|
generics: &Generics,
|
||
|
) -> proc_macro2::TokenStream {
|
||
|
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||
|
quote! {
|
||
|
#[allow(unused_mut)]
|
||
|
impl #impl_generics #bevy_reflect_path::GetTypeRegistration for #type_name #ty_generics #where_clause {
|
||
|
fn get_type_registration() -> #bevy_reflect_path::TypeRegistration {
|
||
|
let mut registration = #bevy_reflect_path::TypeRegistration::of::<#type_name #ty_generics>();
|
||
|
#(registration.insert::<#registration_data>(#bevy_reflect_path::FromType::<#type_name #ty_generics>::from_type());)*
|
||
|
registration
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|