Skip to content

Commit 92a383a

Browse files
committed
Require functions to be Send + Sync
1 parent e4c7aa3 commit 92a383a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

crates/bevy_reflect/src/func/function.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ pub type FunctionResult<'a> = Result<Return<'a>, FunctionError>;
9191
/// ```
9292
pub struct DynamicFunction<'env> {
9393
info: FunctionInfo,
94-
func: Box<dyn for<'a> FnMut(ArgList<'a>, &FunctionInfo) -> FunctionResult<'a> + 'env>,
94+
func: Box<
95+
dyn for<'a> FnMut(ArgList<'a>, &FunctionInfo) -> FunctionResult<'a> + Send + Sync + 'env,
96+
>,
9597
}
9698

9799
impl<'env> DynamicFunction<'env> {
@@ -101,7 +103,9 @@ impl<'env> DynamicFunction<'env> {
101103
///
102104
/// It's important that the function signature matches the provided [`FunctionInfo`].
103105
/// This info is used to validate the arguments and return value.
104-
pub fn new<F: for<'a> FnMut(ArgList<'a>, &FunctionInfo) -> FunctionResult<'a> + 'env>(
106+
pub fn new<
107+
F: for<'a> FnMut(ArgList<'a>, &FunctionInfo) -> FunctionResult<'a> + Send + Sync + 'env,
108+
>(
105109
func: F,
106110
info: FunctionInfo,
107111
) -> Self {

crates/bevy_reflect/src/func/into_function.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ macro_rules! impl_into_function {
118118
R: $crate::func::IntoReturn + $crate::func::args::GetOwnership + $crate::TypePath,
119119
F: FnMut($($Arg),*) -> R + 'env,
120120
F: for<'a> FnMut($($Arg::Item<'a>),*) -> R + 'env,
121+
F: Send + Sync,
121122
{
122123
fn into_function(mut self) -> $crate::func::DynamicFunction<'env> {
123124
const COUNT: usize = count_tts!($($Arg)*);
@@ -166,6 +167,7 @@ macro_rules! impl_into_function {
166167
$($Arg: $crate::func::args::FromArg + $crate::func::args::GetOwnership + $crate::TypePath,)*
167168
F: for<'a> FnMut(&'a Receiver, $($Arg),*) -> &'a R + 'env,
168169
F: for<'a> FnMut(&'a Receiver, $($Arg::Item<'a>),*) -> &'a R + 'env,
170+
F: Send + Sync,
169171
{
170172
fn into_function(mut self) -> $crate::func::DynamicFunction<'env> {
171173
const COUNT: usize = count_tts!(Receiver $($Arg)*);
@@ -217,6 +219,7 @@ macro_rules! impl_into_function {
217219
$($Arg: $crate::func::args::FromArg + $crate::func::args::GetOwnership + $crate::TypePath,)*
218220
F: for<'a> FnMut(&'a mut Receiver, $($Arg),*) -> &'a mut R + 'env,
219221
F: for<'a> FnMut(&'a mut Receiver, $($Arg::Item<'a>),*) -> &'a mut R + 'env,
222+
F: Send + Sync,
220223
{
221224
fn into_function(mut self) -> $crate::func::DynamicFunction<'env> {
222225
const COUNT: usize = count_tts!(Receiver $($Arg)*);
@@ -268,6 +271,7 @@ macro_rules! impl_into_function {
268271
$($Arg: $crate::func::args::FromArg + $crate::func::args::GetOwnership + $crate::TypePath,)*
269272
F: for<'a> FnMut(&'a mut Receiver, $($Arg),*) -> &'a R + 'env,
270273
F: for<'a> FnMut(&'a mut Receiver, $($Arg::Item<'a>),*) -> &'a R + 'env,
274+
F: Send + Sync,
271275
{
272276
fn into_function(mut self) -> $crate::func::DynamicFunction<'env> {
273277
const COUNT: usize = count_tts!(Receiver $($Arg)*);

0 commit comments

Comments
 (0)