@@ -15,6 +15,8 @@ pub enum ReflectPathError<'a> {
1515 index : usize ,
1616 tuple_struct_index : usize ,
1717 } ,
18+ #[ error( "the current tuple doesn't have a field with the index {tuple_index}" ) ]
19+ InvalidTupleIndex { index : usize , tuple_index : usize } ,
1820 #[ error( "the current list doesn't have a value at the index {list_index}" ) ]
1921 InvalidListIndex { index : usize , list_index : usize } ,
2022 #[ error( "encountered an unexpected token `{token}`" ) ]
@@ -282,6 +284,15 @@ fn read_field<'r, 'p>(
282284 } ,
283285 ) ?)
284286 }
287+ ReflectRef :: Tuple ( reflect_tuple) => {
288+ let tuple_index = field. parse :: < usize > ( ) ?;
289+ Ok ( reflect_tuple
290+ . field ( tuple_index)
291+ . ok_or ( ReflectPathError :: InvalidTupleIndex {
292+ index : current_index,
293+ tuple_index,
294+ } ) ?)
295+ }
285296 ReflectRef :: Enum ( reflect_enum) => match reflect_enum. variant_type ( ) {
286297 VariantType :: Struct => {
287298 Ok ( reflect_enum
@@ -334,6 +345,15 @@ fn read_field_mut<'r, 'p>(
334345 } ,
335346 ) ?)
336347 }
348+ ReflectMut :: Tuple ( reflect_tuple) => {
349+ let tuple_index = field. parse :: < usize > ( ) ?;
350+ Ok ( reflect_tuple
351+ . field_mut ( tuple_index)
352+ . ok_or ( ReflectPathError :: InvalidTupleIndex {
353+ index : current_index,
354+ tuple_index,
355+ } ) ?)
356+ }
337357 ReflectMut :: Enum ( reflect_enum) => match reflect_enum. variant_type ( ) {
338358 VariantType :: Struct => {
339359 Ok ( reflect_enum
@@ -467,6 +487,7 @@ mod tests {
467487 unit_variant : F ,
468488 tuple_variant : F ,
469489 struct_variant : F ,
490+ tuple : ( bool , f32 ) ,
470491 }
471492
472493 #[ derive( Reflect ) ]
@@ -504,6 +525,7 @@ mod tests {
504525 unit_variant : F :: Unit ,
505526 tuple_variant : F :: Tuple ( 123 , 321 ) ,
506527 struct_variant : F :: Struct { value : 'm' } ,
528+ tuple : ( true , 1.23 ) ,
507529 } ;
508530
509531 assert_eq ! ( * a. get_path:: <usize >( "w" ) . unwrap( ) , 1 ) ;
@@ -516,6 +538,10 @@ mod tests {
516538 assert_eq ! ( * a. get_path:: <u32 >( "tuple_variant.1" ) . unwrap( ) , 321 ) ;
517539 assert_eq ! ( * a. get_path:: <char >( "struct_variant.value" ) . unwrap( ) , 'm' ) ;
518540
541+ assert_eq ! ( * a. get_path:: <bool >( "tuple.0" ) . unwrap( ) , true ) ;
542+ * a. get_path_mut :: < bool > ( "tuple.0" ) . unwrap ( ) = false ;
543+ assert_eq ! ( * a. get_path:: <bool >( "tuple.0" ) . unwrap( ) , false ) ;
544+
519545 * a. get_path_mut :: < f32 > ( "y[1].baz" ) . unwrap ( ) = 3.0 ;
520546 assert_eq ! ( a. y[ 1 ] . baz, 3.0 ) ;
521547
0 commit comments