Skip to content

Commit 3c2ac36

Browse files
committed
bevy_reflect: Update Reflection documentation (#5841)
# Objective The documentation on `Reflect` doesn't account for the recently added reflection traits: [`Array`](#4701) and [`Enum`](#4761). ## Solution Updated the documentation for `Reflect` to account for the `Array` and `Enum`. Co-authored-by: Gino Valente <[email protected]>
1 parent 17d84e8 commit 3c2ac36

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

crates/bevy_reflect/src/reflect.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ pub enum ReflectMut<'a> {
4747

4848
/// A reflected Rust type.
4949
///
50-
/// Methods for working with particular kinds of Rust type are available using the [`List`], [`Map`],
51-
/// [`Struct`], [`TupleStruct`], and [`Tuple`] subtraits.
50+
/// Methods for working with particular kinds of Rust type are available using the [`Array`], [`List`],
51+
/// [`Map`], [`Tuple`], [`TupleStruct`], [`Struct`], and [`Enum`] subtraits.
5252
///
53-
/// When using `#[derive(Reflect)]` with a struct or tuple struct, the suitable subtrait for that
54-
/// type (`Struct` or `TupleStruct`) is derived automatically.
53+
/// When using `#[derive(Reflect)]` on a struct, tuple struct or enum, the suitable subtrait for that
54+
/// type (`Struct`, `TupleStruct` or `Enum`) is derived automatically.
5555
pub trait Reflect: Any + Send + Sync {
5656
/// Returns the [type name][std::any::type_name] of the underlying type.
5757
fn type_name(&self) -> &str;
@@ -91,8 +91,12 @@ pub trait Reflect: Any + Send + Sync {
9191
/// - If `T` is a [`TupleStruct`] or [`Tuple`], then the value of each
9292
/// numbered field is applied to the corresponding numbered field of
9393
/// `self.` Fields which are not present in both values are ignored.
94-
/// - If `T` is a [`List`], then each element of `value` is applied to the
95-
/// corresponding element of `self`. Up to `self.len()` items are applied,
94+
/// - If `T` is an [`Enum`], then the variant of `self` is `updated` to match
95+
/// the variant of `value`. The corresponding fields of that variant are
96+
/// applied from `value` onto `self`. Fields which are not present in both
97+
/// values are ignored.
98+
/// - If `T` is a [`List`] or [`Array`], then each element of `value` is applied
99+
/// to the corresponding element of `self`. Up to `self.len()` items are applied,
96100
/// and excess elements in `value` are appended to `self`.
97101
/// - If `T` is a [`Map`], then for each key in `value`, the associated
98102
/// value is applied to the value associated with the same key in `self`.
@@ -102,7 +106,7 @@ pub trait Reflect: Any + Send + Sync {
102106
///
103107
/// Note that `Reflect` must be implemented manually for [`List`]s and
104108
/// [`Map`]s in order to achieve the correct semantics, as derived
105-
/// implementations will have the semantics for [`Struct`], [`TupleStruct`]
109+
/// implementations will have the semantics for [`Struct`], [`TupleStruct`], [`Enum`]
106110
/// or none of the above depending on the kind of type. For lists and maps, use the
107111
/// [`list_apply`] and [`map_apply`] helper functions when implementing this method.
108112
///
@@ -137,11 +141,11 @@ pub trait Reflect: Any + Send + Sync {
137141

138142
/// Clones the value as a `Reflect` trait object.
139143
///
140-
/// When deriving `Reflect` for a struct or struct tuple, the value is
141-
/// cloned via [`Struct::clone_dynamic`] (resp.
142-
/// [`TupleStruct::clone_dynamic`]). Implementors of other `Reflect`
143-
/// subtraits (e.g. [`List`], [`Map`]) should use those subtraits'
144-
/// respective `clone_dynamic` methods.
144+
/// When deriving `Reflect` for a struct, tuple struct or enum, the value is
145+
/// cloned via [`Struct::clone_dynamic`], [`TupleStruct::clone_dynamic`],
146+
/// or [`Enum::clone_dynamic`], respectively.
147+
/// Implementors of other `Reflect` subtraits (e.g. [`List`], [`Map`]) should
148+
/// use those subtraits' respective `clone_dynamic` methods.
145149
fn clone_value(&self) -> Box<dyn Reflect>;
146150

147151
/// Returns a hash of the value (which includes the type).

0 commit comments

Comments
 (0)