From 3c2ac3651f30db62270ef58ef7cc16d86064e4fa Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Fri, 2 Sep 2022 16:17:45 +0000 Subject: [PATCH] bevy_reflect: Update `Reflection` documentation (#5841) # Objective The documentation on `Reflect` doesn't account for the recently added reflection traits: [`Array`](https://github.com/bevyengine/bevy/pull/4701) and [`Enum`](https://github.com/bevyengine/bevy/pull/4761). ## Solution Updated the documentation for `Reflect` to account for the `Array` and `Enum`. Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com> --- crates/bevy_reflect/src/reflect.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/crates/bevy_reflect/src/reflect.rs b/crates/bevy_reflect/src/reflect.rs index 3b3b7c274445a..fb8285fd9de0c 100644 --- a/crates/bevy_reflect/src/reflect.rs +++ b/crates/bevy_reflect/src/reflect.rs @@ -47,11 +47,11 @@ pub enum ReflectMut<'a> { /// A reflected Rust type. /// -/// Methods for working with particular kinds of Rust type are available using the [`List`], [`Map`], -/// [`Struct`], [`TupleStruct`], and [`Tuple`] subtraits. +/// Methods for working with particular kinds of Rust type are available using the [`Array`], [`List`], +/// [`Map`], [`Tuple`], [`TupleStruct`], [`Struct`], and [`Enum`] subtraits. /// -/// When using `#[derive(Reflect)]` with a struct or tuple struct, the suitable subtrait for that -/// type (`Struct` or `TupleStruct`) is derived automatically. +/// When using `#[derive(Reflect)]` on a struct, tuple struct or enum, the suitable subtrait for that +/// type (`Struct`, `TupleStruct` or `Enum`) is derived automatically. pub trait Reflect: Any + Send + Sync { /// Returns the [type name][std::any::type_name] of the underlying type. fn type_name(&self) -> &str; @@ -91,8 +91,12 @@ pub trait Reflect: Any + Send + Sync { /// - If `T` is a [`TupleStruct`] or [`Tuple`], then the value of each /// numbered field is applied to the corresponding numbered field of /// `self.` Fields which are not present in both values are ignored. - /// - If `T` is a [`List`], then each element of `value` is applied to the - /// corresponding element of `self`. Up to `self.len()` items are applied, + /// - If `T` is an [`Enum`], then the variant of `self` is `updated` to match + /// the variant of `value`. The corresponding fields of that variant are + /// applied from `value` onto `self`. Fields which are not present in both + /// values are ignored. + /// - If `T` is a [`List`] or [`Array`], then each element of `value` is applied + /// to the corresponding element of `self`. Up to `self.len()` items are applied, /// and excess elements in `value` are appended to `self`. /// - If `T` is a [`Map`], then for each key in `value`, the associated /// value is applied to the value associated with the same key in `self`. @@ -102,7 +106,7 @@ pub trait Reflect: Any + Send + Sync { /// /// Note that `Reflect` must be implemented manually for [`List`]s and /// [`Map`]s in order to achieve the correct semantics, as derived - /// implementations will have the semantics for [`Struct`], [`TupleStruct`] + /// implementations will have the semantics for [`Struct`], [`TupleStruct`], [`Enum`] /// or none of the above depending on the kind of type. For lists and maps, use the /// [`list_apply`] and [`map_apply`] helper functions when implementing this method. /// @@ -137,11 +141,11 @@ pub trait Reflect: Any + Send + Sync { /// Clones the value as a `Reflect` trait object. /// - /// When deriving `Reflect` for a struct or struct tuple, the value is - /// cloned via [`Struct::clone_dynamic`] (resp. - /// [`TupleStruct::clone_dynamic`]). Implementors of other `Reflect` - /// subtraits (e.g. [`List`], [`Map`]) should use those subtraits' - /// respective `clone_dynamic` methods. + /// When deriving `Reflect` for a struct, tuple struct or enum, the value is + /// cloned via [`Struct::clone_dynamic`], [`TupleStruct::clone_dynamic`], + /// or [`Enum::clone_dynamic`], respectively. + /// Implementors of other `Reflect` subtraits (e.g. [`List`], [`Map`]) should + /// use those subtraits' respective `clone_dynamic` methods. fn clone_value(&self) -> Box; /// Returns a hash of the value (which includes the type).