Skip to content

Commit

Permalink
Remove Return::Unit variant (#15484)
Browse files Browse the repository at this point in the history
# 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>
  • Loading branch information
hooded-shrimp and MrGVSV authored Sep 28, 2024
1 parent 1175cf7 commit 7ee5143
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions crates/bevy_reflect/src/func/return_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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.
Expand Down Expand Up @@ -81,7 +89,7 @@ pub trait IntoReturn {

impl IntoReturn for () {
fn into_return<'a>(self) -> Return<'a> {
Return::Unit
Return::unit()
}
}

Expand Down

0 comments on commit 7ee5143

Please sign in to comment.