diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index b06302296e1ad..6b770f3a01e7b 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -35,8 +35,7 @@ impl Plugin for CorePlugin { app.register_type::>() .register_type::>() .register_type::() - .register_type::() - .register_type::>(); + .register_type::(); register_rust_types(app); register_math_types(app); @@ -44,21 +43,7 @@ impl Plugin for CorePlugin { } fn register_rust_types(app: &mut App) { - app.register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() + app.register_type::>() .register_type::() .register_type::>(); } diff --git a/crates/bevy_reflect/src/type_registry.rs b/crates/bevy_reflect/src/type_registry.rs index 5155895178021..c663cae6decdf 100644 --- a/crates/bevy_reflect/src/type_registry.rs +++ b/crates/bevy_reflect/src/type_registry.rs @@ -6,7 +6,6 @@ use serde::Deserialize; use std::{any::TypeId, fmt::Debug, sync::Arc}; /// A registry of reflected types. -#[derive(Default)] pub struct TypeRegistry { registrations: HashMap, short_name_to_id: HashMap, @@ -35,7 +34,44 @@ pub trait GetTypeRegistration { fn get_type_registration() -> TypeRegistration; } +impl Default for TypeRegistry { + fn default() -> Self { + Self::new() + } +} + impl TypeRegistry { + /// Create a type registry with *no* registered types. + pub fn empty() -> Self { + Self { + registrations: Default::default(), + short_name_to_id: Default::default(), + full_name_to_id: Default::default(), + ambiguous_names: Default::default(), + } + } + + /// Create a type registry with default registrations for primitive types. + pub fn new() -> Self { + let mut registry = Self::empty(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry.register::(); + registry + } + /// Registers the type `T`. pub fn register(&mut self) where