forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration.rs
31 lines (29 loc) · 1.42 KB
/
registration.rs
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
28
29
30
31
//! 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,
insert_serialization_data: bool,
) -> proc_macro2::TokenStream {
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
let serialization_data = insert_serialization_data.then_some(quote! {
registration.insert::<#bevy_reflect_path::serde::SerializationData>(#bevy_reflect_path::FromType::<#type_name #ty_generics>::from_type());
});
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::<#bevy_reflect_path::ReflectFromPtr>(#bevy_reflect_path::FromType::<#type_name #ty_generics>::from_type());
#serialization_data
#(registration.insert::<#registration_data>(#bevy_reflect_path::FromType::<#type_name #ty_generics>::from_type());)*
registration
}
}
}
}