Skip to content

Commit 8d95a09

Browse files
committed
Added DynamicTyped
1 parent b9b43ad commit 8d95a09

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

crates/bevy_reflect/src/reflect.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
array_debug, enum_debug, list_debug, map_debug, serde::Serializable, struct_debug, tuple_debug,
3-
tuple_struct_debug, Array, DynamicTypePath, Enum, List, Map, Set, Struct, Tuple, TupleStruct,
4-
TypeInfo, TypePath, Typed, ValueInfo,
3+
tuple_struct_debug, Array, DynamicTypePath, DynamicTyped, Enum, List, Map, Set, Struct, Tuple,
4+
TupleStruct, TypeInfo, TypePath, Typed, ValueInfo,
55
};
66
use std::{
77
any::{Any, TypeId},
@@ -408,7 +408,7 @@ where
408408
message = "`{Self}` does not implement `Reflect` so cannot be fully reflected",
409409
note = "consider annotating `{Self}` with `#[derive(Reflect)]`"
410410
)]
411-
pub trait Reflect: PartialReflect + Any {
411+
pub trait Reflect: PartialReflect + DynamicTyped + Any {
412412
/// Returns the value as a [`Box<dyn Any>`][std::any::Any].
413413
///
414414
/// For remote wrapper types, this will return the remote type instead.

crates/bevy_reflect/src/type_info.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ impl MaybeTyped for DynamicArray {}
136136

137137
impl MaybeTyped for DynamicTuple {}
138138

139+
/// Dynamic dispatch for [`Typed`].
140+
///
141+
/// Since this is a supertrait of [`Reflect`] its methods can be called on a `dyn Reflect`.
142+
///
143+
/// [`Reflect`]: crate::Reflect
144+
#[diagnostic::on_unimplemented(
145+
message = "`{Self}` can not provide dynamic type information through reflection",
146+
note = "consider annotating `{Self}` with `#[derive(Reflect)]`"
147+
)]
148+
pub trait DynamicTyped {
149+
/// See [`Typed::type_info`].
150+
fn reflect_type_info(&self) -> &'static TypeInfo;
151+
}
152+
153+
impl<T: Typed> DynamicTyped for T {
154+
#[inline]
155+
fn reflect_type_info(&self) -> &'static TypeInfo {
156+
Self::type_info()
157+
}
158+
}
159+
139160
/// A [`TypeInfo`]-specific error.
140161
#[derive(Debug, Error)]
141162
pub enum TypeInfoError {

0 commit comments

Comments
 (0)