Skip to content

Commit

Permalink
bevy_reflect: Update Reflection documentation (bevyengine#5841)
Browse files Browse the repository at this point in the history
# Objective

The documentation on `Reflect` doesn't account for the recently added reflection traits: [`Array`](bevyengine#4701) and [`Enum`](bevyengine#4761).

## Solution

Updated the documentation for `Reflect` to account for the `Array` and `Enum`.


Co-authored-by: Gino Valente <[email protected]>
  • Loading branch information
2 people authored and james7132 committed Oct 28, 2022
1 parent ae7c879 commit aa8293d
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions crates/bevy_reflect/src/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`.
Expand All @@ -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.
///
Expand Down Expand Up @@ -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<dyn Reflect>;

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

0 comments on commit aa8293d

Please sign in to comment.