From 7ee5143d45f9246f9cffc52e916ae12d85a71779 Mon Sep 17 00:00:00 2001 From: hshrimp <182684536+hooded-shrimp@users.noreply.github.com> Date: Sat, 28 Sep 2024 09:26:55 -0700 Subject: [PATCH] Remove `Return::Unit` variant (#15484) # Objective - Fixes #15447 ## Solution - Remove the `Return::Unit` variant and use a `Return::Owned` variant holding a unit `()` type. ## Migration Guide - Removed the `Return::Unit` variant; use `Return::unit()` instead. --------- Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com> --- crates/bevy_reflect/src/func/return_type.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/bevy_reflect/src/func/return_type.rs b/crates/bevy_reflect/src/func/return_type.rs index 9ad44018d9..124ce4d735 100644 --- a/crates/bevy_reflect/src/func/return_type.rs +++ b/crates/bevy_reflect/src/func/return_type.rs @@ -6,9 +6,9 @@ use crate::PartialReflect; /// [`DynamicFunctionMut`]: crate::func::DynamicFunctionMut #[derive(Debug)] pub enum Return<'a> { - /// The function returns nothing (i.e. it returns `()`). - Unit, /// The function returns an owned value. + /// + /// This includes functions that return nothing (i.e. they return `()`). Owned(Box), /// The function returns a reference to a value. Ref(&'a dyn PartialReflect), @@ -17,9 +17,17 @@ pub enum Return<'a> { } impl<'a> Return<'a> { - /// Returns `true` if the return value is [`Self::Unit`]. + /// Creates an [`Owned`](Self::Owned) unit (`()`) type. + pub fn unit() -> Self { + Self::Owned(Box::new(())) + } + + /// Returns `true` if the return value is an [`Owned`](Self::Owned) unit (`()`) type. pub fn is_unit(&self) -> bool { - matches!(self, Return::Unit) + match self { + Return::Owned(val) => val.represents::<()>(), + _ => false, + } } /// Unwraps the return value as an owned value. @@ -81,7 +89,7 @@ pub trait IntoReturn { impl IntoReturn for () { fn into_return<'a>(self) -> Return<'a> { - Return::Unit + Return::unit() } }