@@ -38,10 +38,6 @@ pub trait GetTypeRegistration {
3838     /// 
3939     /// This method is called by [`TypeRegistry::register`] to register any other required types. 
4040     /// Often, this is done for fields of structs and enum variants to ensure all types are properly registered. 
41-      /// 
42-      /// If manually implementing, it is _highly_ recommended to use [`TypeRegistry::try_register`] for these dependent types. 
43-      /// Using this method allows the type to be skipped if it has already been registered, thus preventing any 
44-      /// undesired overwrites and reducing registration costs. 
4541     #[ allow( unused_variables) ]  
4642    fn  register_type_dependencies ( registry :  & mut  TypeRegistry )  { } 
4743} 
@@ -84,39 +80,53 @@ impl TypeRegistry {
8480        registry
8581    } 
8682
87-     /// Registers the type `T`, adding reflect data as specified in the [`Reflect`] derive: 
83+     /// Attempts to register the type `T` if it has not yet been registered already. 
84+      /// 
85+      /// If the registration for type `T` already exists, it will not be registered again. 
86+      /// To register the type, overwriting any existing registration, use [register](Self::register) instead. 
87+      /// 
88+      /// Additionally, this will add the reflect [data](TypeData) as specified in the [`Reflect`] derive: 
8889     /// ```rust,ignore 
8990     /// #[derive(Reflect)] 
9091     /// #[reflect(Component, Serialize, Deserialize)] // will register ReflectComponent, ReflectSerialize, ReflectDeserialize 
92+      /// struct Foo; 
9193     /// ``` 
9294     pub  fn  register < T > ( & mut  self ) 
9395    where 
9496        T :  GetTypeRegistration , 
9597    { 
96-         self . add_registration ( T :: get_type_registration ( ) ) ; 
98+         if  !self . add_registration ( T :: get_type_registration ( ) )  { 
99+             return ; 
100+         } 
101+ 
97102        T :: register_type_dependencies ( self ) ; 
98103    } 
99104
100-     /// Attempts to register the type `T` if it has not yet been registered already . 
105+     /// Attempts to register the type described by `registration` . 
101106     /// 
102-      /// If the registration for type `T`  already exists, it will not be registered again. 
107+      /// If the registration for the type  already exists, it will not be registered again. 
103108     /// 
104-      /// To register the type, overwriting any existing registration, use [register](Self::register) instead. 
105-      pub  fn  try_register < T > ( & mut  self ) 
106-     where 
107-         T :  GetTypeRegistration  + ' static , 
108-     { 
109-         if  !self . contains ( TypeId :: of :: < T > ( ) )  { 
110-             self . register :: < T > ( ) ; 
109+      /// To forcibly register the type, overwriting any existing registration, use the 
110+      /// [`force_add_registration`](Self::force_add_registration) method instead. 
111+      /// 
112+      /// Returns `true` if the registration was successfully added, 
113+      /// or `false` if it already exists. 
114+      pub  fn  add_registration ( & mut  self ,  registration :  TypeRegistration )  -> bool  { 
115+         if  self . contains ( registration. type_id ( ) )  { 
116+             false 
117+         }  else  { 
118+             self . force_add_registration ( registration) ; 
119+             true 
111120        } 
112121    } 
113122
114123    /// Registers the type described by `registration`. 
115-      pub  fn  add_registration ( & mut  self ,  registration :  TypeRegistration )  { 
116-         if  self . registrations . contains_key ( & registration. type_id ( ) )  { 
117-             return ; 
118-         } 
119- 
124+      /// 
125+      /// If the registration for the type already exists, it will be overwritten. 
126+      /// 
127+      /// To avoid overwriting existing registrations, it's recommended to use the 
128+      /// [`register`](Self::register) or [`add_registration`](Self::add_registration) methods instead. 
129+      pub  fn  force_add_registration ( & mut  self ,  registration :  TypeRegistration )  { 
120130        let  short_name = registration. short_name . to_string ( ) ; 
121131        if  self . short_name_to_id . contains_key ( & short_name) 
122132            || self . ambiguous_names . contains ( & short_name) 
0 commit comments