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>
This commit is contained in:
hshrimp 2024-09-28 09:26:55 -07:00 committed by GitHub
parent 1175cf7920
commit 7ee5143d45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<dyn PartialReflect>),
/// 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()
}
}