Skip to content

Commit 7974319

Browse files
committed
Tuple should have fields instead of index
1 parent 53ace23 commit 7974319

File tree

2 files changed

+9
-52
lines changed

2 files changed

+9
-52
lines changed

crates/bevy_reflect/src/from_reflect.rs

+7-50
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ pub enum FromReflectError {
185185

186186
/// The source type did not have a field at index given by the parameter `index`.
187187
///
188-
/// This error is given by types of [kind](ReflectKind) [`TupleStruct`](crate::TupleStruct) and
189-
/// [`Enum`](crate::Enum).
188+
/// This error is given by types of [kind](ReflectKind) [`TupleStruct`](crate::TupleStruct),
189+
/// [`Tuple`](crate::Tuple) and [`Enum`](crate::Enum).
190190
#[error("The reflected type `{}` of kind {} cannot be converted to type `{}` due to a missing field at index {}",
191191
.from_type.type_name(), self.display_from_kind(), .to_type.type_name(), .index)]
192192
MissingUnnamedField {
@@ -203,25 +203,6 @@ pub enum FromReflectError {
203203
index: usize,
204204
},
205205

206-
/// The source type did not have a value at index given by the parameter `index`.
207-
///
208-
/// This error is given by types of [kind](ReflectKind) [`Tuple`](crate::Tuple).
209-
#[error("The reflected type `{}` of kind {} cannot be converted to type `{}` due to a missing value at index {}",
210-
.from_type.type_name(), self.display_from_kind(), .to_type.type_name(), .index)]
211-
MissingIndex {
212-
/// [`TypeInfo`] of the source type.
213-
from_type: &'static TypeInfo,
214-
215-
/// [`ReflectKind`] of the source type.
216-
from_kind: ReflectKind,
217-
218-
/// [`TypeInfo`] of the target type.
219-
to_type: &'static TypeInfo,
220-
221-
/// Index of missing value in source type.
222-
index: usize,
223-
},
224-
225206
/// The target type did not have a variant with name given by the parameter `variant`.
226207
///
227208
/// This error is given by types of [kind](ReflectKind) [`Enum`](crate::Enum).
@@ -270,8 +251,8 @@ pub enum FromReflectError {
270251
///
271252
/// Use [`Error::source`](std::error::Error::source) to get the underlying error.
272253
///
273-
/// This error is given by types of [kind](ReflectKind) [`TupleStruct`](crate::TupleStruct)
274-
/// and [`Enum`](crate::Enum).
254+
/// This error is given by types of [kind](ReflectKind) [`TupleStruct`](crate::TupleStruct),
255+
/// [`Tuple`](crate::Tuple) and [`Enum`](crate::Enum).
275256
#[error("The reflected type `{}` of kind {} cannot be converted to type `{}` due to an error in the field at index {}",
276257
.from_type.type_name(), self.display_from_kind(), .to_type.type_name(), .index)]
277258
UnnamedFieldError {
@@ -296,7 +277,7 @@ pub enum FromReflectError {
296277
/// Use [`Error::source`](std::error::Error::source) to get the underlying error.
297278
///
298279
/// This error is given by types of [kind](ReflectKind) [`List`](crate::List) and
299-
/// [`Enum`](crate::Enum).
280+
/// [`Array`](crate::Array).
300281
#[error("The reflected type `{}` of kind {} cannot be converted to type `{}` due to an error in the value at index `{}`",
301282
.from_type.type_name(), self.display_from_kind(), .to_type.type_name(), .index)]
302283
IndexError {
@@ -391,7 +372,6 @@ impl FromReflectError {
391372
| Self::InvalidLength { from_type, .. }
392373
| Self::MissingNamedField { from_type, .. }
393374
| Self::MissingUnnamedField { from_type, .. }
394-
| Self::MissingIndex { from_type, .. }
395375
| Self::MissingVariant { from_type, .. }
396376
| Self::NamedFieldError { from_type, .. }
397377
| Self::UnnamedFieldError { from_type, .. }
@@ -409,7 +389,6 @@ impl FromReflectError {
409389
| Self::InvalidLength { to_type, .. }
410390
| Self::MissingNamedField { to_type, .. }
411391
| Self::MissingUnnamedField { to_type, .. }
412-
| Self::MissingIndex { to_type, .. }
413392
| Self::MissingVariant { to_type, .. }
414393
| Self::NamedFieldError { to_type, .. }
415394
| Self::UnnamedFieldError { to_type, .. }
@@ -427,7 +406,6 @@ impl FromReflectError {
427406
| Self::InvalidLength { from_kind, .. }
428407
| Self::MissingNamedField { from_kind, .. }
429408
| Self::MissingUnnamedField { from_kind, .. }
430-
| Self::MissingIndex { from_kind, .. }
431409
| Self::MissingVariant { from_kind, .. }
432410
| Self::NamedFieldError { from_kind, .. }
433411
| Self::UnnamedFieldError { from_kind, .. }
@@ -469,8 +447,8 @@ impl FromReflectError {
469447
mod tests {
470448
use crate as bevy_reflect;
471449
use crate::{
472-
DynamicEnum, DynamicList, DynamicMap, DynamicStruct, DynamicTuple, DynamicTupleStruct,
473-
DynamicVariant, FromReflect, FromReflectError, Reflect, ReflectKind, TypeInfo,
450+
DynamicEnum, DynamicList, DynamicMap, DynamicStruct, DynamicTupleStruct, DynamicVariant,
451+
FromReflect, FromReflectError, Reflect, ReflectKind, TypeInfo,
474452
};
475453
use bevy_utils::HashMap;
476454
use std::borrow::Cow;
@@ -568,27 +546,6 @@ mod tests {
568546
);
569547
}
570548

571-
#[test]
572-
fn check_missing_index() {
573-
let mut dyn_tuple = DynamicTuple::default();
574-
dyn_tuple.insert(5);
575-
576-
let result = <(i32, i32)>::from_reflect(&dyn_tuple);
577-
578-
assert!(
579-
matches!(
580-
result,
581-
Err(FromReflectError::MissingIndex {
582-
from_type: TypeInfo::Dynamic(_),
583-
from_kind: ReflectKind::Tuple,
584-
to_type: TypeInfo::Tuple(_),
585-
index: 1,
586-
})
587-
),
588-
"Incorrect error handling of FromReflectError::MissingIndex"
589-
);
590-
}
591-
592549
#[test]
593550
fn check_missing_variant() {
594551
#[derive(Reflect, FromReflect)]

crates/bevy_reflect/src/tuple.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,13 @@ macro_rules! impl_reflect_tuple {
604604
$(
605605
<$name as FromReflect>::from_reflect(
606606
_ref_tuple.field($index)
607-
.ok_or_else(|| FromReflectError::MissingIndex {
607+
.ok_or_else(|| FromReflectError::MissingUnnamedField {
608608
from_type: reflect.get_type_info(),
609609
from_kind: reflect.reflect_kind(),
610610
to_type: Self::type_info(),
611611
index: $index,
612612
})?
613-
).map_err(|err| FromReflectError::IndexError {
613+
).map_err(|err| FromReflectError::UnnamedFieldError {
614614
from_type: reflect.get_type_info(),
615615
from_kind: reflect.reflect_kind(),
616616
to_type: Self::type_info(),

0 commit comments

Comments
 (0)