From 6d25545c516b2fb7698334c428b9cefdee12281e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Thu, 2 May 2024 20:28:24 +0200 Subject: [PATCH] Implement Reflect for Result as enum (#13182) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective - Make `Result` implement Reflect such that it is an Enum rather than a Value - Fixes #13178 ## Solution - Use the correct macro ## Testing - Did you test these changes? I tried it out locally, and it does what it says on the tin. Not sure how to test it in context of the crate? --- ## Changelog ### Changed - Result now uses `ReflectKind::Enum` rather than `ReflectKind::Value`, allowing for inspection of its constituents ## Migration Guide `Result` has had its `Reflect` implementation changed to align it with `Option` and its intended semantics: A carrier of either an `Ok` or `Err` value, and the ability to access it. To achieve this it is no longer a `ReflectKind::Value` but rather a `ReflectKind::Enum` and as such carries these changes with it: For `Result` - Both `T` and `E` no longer require to be `Clone` and now require to be `FromReflect` - ` as Reflect>::reflect_*` now returns a `ReflectKind::Enum`, so any code that previously relied on it being a `Value` kind will have to be adapted. - `Result` now implements `Enum` Since the migration is highly dependent on the previous usage, no automatic upgrade path can be given. Signed-off-by: Marcel Müller --- crates/bevy_reflect/src/impls/std.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index cb6edb6302..55bdd75e36 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -96,10 +96,6 @@ impl_reflect_value!(::std::path::PathBuf( Default )); impl_reflect_value!(::std::any::TypeId(Debug, Hash, PartialEq,)); -impl_reflect_value!( - ::core::result::Result < T: Clone + Reflect + TypePath, - E: Clone + Reflect + TypePath > () -); impl_reflect_value!(::std::collections::BTreeSet()); impl_reflect_value!(::std::collections::HashSet()); impl_reflect_value!(::bevy_utils::hashbrown::HashSet()); @@ -1006,6 +1002,14 @@ impl_reflect! { } } +impl_reflect! { + #[type_path = "core::result"] + enum Result { + Ok(T), + Err(E), + } +} + impl TypePath for &'static T { fn type_path() -> &'static str { static CELL: GenericTypePathCell = GenericTypePathCell::new();