Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
feyokorenhof committed Nov 29, 2022
1 parent 35532d2 commit 85fde81
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_reflect/bevy_reflect_derive/src/impls/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> TokenStream {
*self = #variant_constructors
})*
name => {
return Err(#bevy_reflect_path::ApplyError::WrongType("TODO".to_string()));
return Err(#bevy_reflect_path::ApplyError::UnknownVariant(name.to_string(), std::any::type_name::<Self>().to_string()));
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions crates/bevy_reflect/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ pub fn array_apply<A: Array>(array: &mut A, reflect: &dyn Reflect) {
}
}

/// Tries to apply the reflected [array](Array) data to the given [array](Array) and
/// returns a Result.
///
/// # Errors
///
/// * Returns an [`ApplyError::DifferentSize`] if the two arrays have differing lengths.
/// * Returns an [`ApplyError::MismatchedTypes`] if the reflected value is not a
/// [valid array](ReflectRef::Array).
///
#[inline]
pub fn array_try_apply<A: Array>(array: &mut A, reflect: &dyn Reflect) -> Result<(), ApplyError> {
if let ReflectRef::Array(reflect_array) = reflect.reflect_ref() {
Expand Down
9 changes: 9 additions & 0 deletions crates/bevy_reflect/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ pub fn list_apply<L: List>(a: &mut L, b: &dyn Reflect) {
}
}

/// Tries to apply the elements of `b` to the corresponding elements of `a` and
/// returns a Result.
///
/// If the length of `b` is greater than that of `a`, the excess elements of `b`
/// are cloned and appended to `a`.
///
/// # Errors
///
/// This function returns an [`ApplyError::MismatchedTypes`] if `b` is not a list.
#[inline]
pub fn list_try_apply<L: List>(a: &mut L, b: &dyn Reflect) -> Result<(), ApplyError> {
if let ReflectRef::List(list_value) = b.reflect_ref() {
Expand Down
8 changes: 8 additions & 0 deletions crates/bevy_reflect/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ pub fn map_apply<M: Map>(a: &mut M, b: &dyn Reflect) {
}
}

/// Tries to apply the elements of reflected map `b` to the corresponding elements of map `a`
/// and returns a Result.
///
/// If a key from `b` does not exist in `a`, the value is cloned and inserted.
///
/// # Errors
///
/// This function returns an [`ApplyError::MismatchedTypes`] if `b` is not a reflected map.
#[inline]
pub fn map_try_apply<M: Map>(a: &mut M, b: &dyn Reflect) -> Result<(), ApplyError> {
if let ReflectRef::Map(map_value) = b.reflect_ref() {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_reflect/src/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub trait Reflect: Any + Send + Sync {
/// panicking.
///
/// Note: the value you call this function on will end up being partially mutated
/// if this function runs into an error along the way (types with nested values like lists).
/// if this function runs into an error along the way (i.e. types with nested values like lists).
///
/// If a type implements a subtrait of `Reflect`, then the semantics of this
/// method are as follows:
Expand Down Expand Up @@ -201,7 +201,7 @@ pub trait Reflect: Any + Send + Sync {
///
/// # Errors
///
/// Derived implementations of this method will return an error:
/// Derived implementations of this method will return an [`ApplyError`]:
/// - If the type of `value` is not of the same kind as `T` (e.g. if `T` is
/// a `List`, while `value` is a `Struct`).
/// - If `T` is any complex type and the corresponding fields or elements of
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_reflect/src/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ pub fn tuple_apply<T: Tuple>(a: &mut T, b: &dyn Reflect) {
}
}

/// Tries to apply the elements of `b` to the corresponding elements of `a` and
/// returns a Result.
///
/// # Errors
///
/// This function returns an [`ApplyError::MismatchedTypes`] if `b` is not a tuple.
#[inline]
pub fn tuple_try_apply<T: Tuple>(a: &mut T, b: &dyn Reflect) -> Result<(), ApplyError> {
if let ReflectRef::Tuple(tuple) = b.reflect_ref() {
Expand Down

0 comments on commit 85fde81

Please sign in to comment.