@@ -35,7 +35,7 @@ impl_reflect_value!(HashSet<T: Serialize + Hash + Eq + Clone + for<'de> Deserial
35
35
impl_reflect_value ! ( Range <T : Serialize + Clone + for <' de> Deserialize <' de> + Send + Sync + ' static >( Serialize , Deserialize ) ) ;
36
36
impl_reflect_value ! ( Duration ) ;
37
37
38
- impl < T : Reflect > List for Vec < T > {
38
+ impl < T : Reflect + Default > List for Vec < T > {
39
39
fn get ( & self , index : usize ) -> Option < & dyn Reflect > {
40
40
<[ T ] >:: get ( self , index) . map ( |value| value as & dyn Reflect )
41
41
}
@@ -57,17 +57,17 @@ impl<T: Reflect> List for Vec<T> {
57
57
58
58
fn push ( & mut self , value : Box < dyn Reflect > ) {
59
59
let value = value. take :: < T > ( ) . unwrap_or_else ( |value| {
60
- panic ! (
61
- "Attempted to push invalid value of type {}." ,
62
- value. type_name ( )
63
- )
60
+ // If `value` is not of the same type, it may be a dynamic type that needs to be applied
61
+ let mut new_value = T :: default ( ) ;
62
+ ( & mut new_value as & mut dyn Reflect ) . apply ( value. as_ref ( ) ) ;
63
+ new_value
64
64
} ) ;
65
65
Vec :: push ( self , value) ;
66
66
}
67
67
}
68
68
69
69
// SAFE: any and any_mut both return self
70
- unsafe impl < T : Reflect > Reflect for Vec < T > {
70
+ unsafe impl < T : Reflect + Default > Reflect for Vec < T > {
71
71
fn type_name ( & self ) -> & str {
72
72
std:: any:: type_name :: < Self > ( )
73
73
}
@@ -114,7 +114,7 @@ unsafe impl<T: Reflect> Reflect for Vec<T> {
114
114
}
115
115
}
116
116
117
- impl < T : Reflect + for < ' de > Deserialize < ' de > > GetTypeRegistration for Vec < T > {
117
+ impl < T : Reflect + Default + for < ' de > Deserialize < ' de > > GetTypeRegistration for Vec < T > {
118
118
fn get_type_registration ( ) -> TypeRegistration {
119
119
let mut registration = TypeRegistration :: of :: < Vec < T > > ( ) ;
120
120
registration. insert :: < ReflectDeserialize > ( FromType :: < Vec < T > > :: from_type ( ) ) ;
0 commit comments