diff --git a/Cargo.toml b/Cargo.toml index af2d9d356cb59..163a780633615 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"] license = "MIT OR Apache-2.0" repository = "https://github.com/bevyengine/bevy" documentation = "https://docs.rs/bevy" -rust-version = "1.85.0" +rust-version = "1.86.0" [workspace] resolver = "2" diff --git a/benches/benches/bevy_reflect/list.rs b/benches/benches/bevy_reflect/list.rs index fcbe59accdbc7..b55d7a746268c 100644 --- a/benches/benches/bevy_reflect/list.rs +++ b/benches/benches/bevy_reflect/list.rs @@ -47,7 +47,7 @@ fn list_apply( ) where M: Measurement, LBase: List, - LPatch: List, + LPatch: List + Send + Sync, F1: Fn(usize) -> F2, F2: Fn() -> LBase, F3: Fn(usize) -> LPatch, diff --git a/benches/benches/bevy_reflect/map.rs b/benches/benches/bevy_reflect/map.rs index e35af1c992b17..8b93ab7a1481f 100644 --- a/benches/benches/bevy_reflect/map.rs +++ b/benches/benches/bevy_reflect/map.rs @@ -53,7 +53,7 @@ fn map_apply( ) where M: Measurement, MBase: Map, - MPatch: Map, + MPatch: Map + Send + Sync, F1: Fn(usize) -> F2, F2: Fn() -> MBase, F3: Fn(usize) -> MPatch, diff --git a/benches/benches/bevy_reflect/struct.rs b/benches/benches/bevy_reflect/struct.rs index 7750213b6dd76..aff4dd1cc3a07 100644 --- a/benches/benches/bevy_reflect/struct.rs +++ b/benches/benches/bevy_reflect/struct.rs @@ -73,7 +73,7 @@ fn concrete_struct_apply(criterion: &mut Criterion) { // Use functions that produce trait objects of varying concrete types as the // input to the benchmark. - let inputs: &[fn() -> (Box, Box)] = &[ + let inputs: &[fn() -> (Box, Box)] = &[ || (Box::new(Struct16::default()), Box::new(Struct16::default())), || (Box::new(Struct32::default()), Box::new(Struct32::default())), || (Box::new(Struct64::default()), Box::new(Struct64::default())), @@ -243,7 +243,7 @@ fn dynamic_struct_to_dynamic_struct(criterion: &mut Criterion) { fn dynamic_struct_apply(criterion: &mut Criterion) { let mut group = create_group(criterion, bench!("dynamic_struct_apply")); - let patches: &[(fn() -> Box, usize)] = &[ + let patches: &[(fn() -> Box, usize)] = &[ (|| Box::new(Struct16::default()), 16), (|| Box::new(Struct32::default()), 32), (|| Box::new(Struct64::default()), 64), @@ -612,12 +612,12 @@ struct Struct128 { } #[derive(Clone, Default, Reflect)] -struct GenericStruct1 { +struct GenericStruct1 { field_0: T, } #[derive(Clone, Default, Reflect)] -struct GenericStruct16 { +struct GenericStruct16 { field_0: T, field_1: T, field_2: T, @@ -637,7 +637,7 @@ struct GenericStruct16 { } #[derive(Clone, Default, Reflect)] -struct GenericStruct32 { +struct GenericStruct32 { field_0: T, field_1: T, field_2: T, @@ -673,7 +673,7 @@ struct GenericStruct32 { } #[derive(Clone, Default, Reflect)] -struct GenericStruct64 { +struct GenericStruct64 { field_0: T, field_1: T, field_2: T, @@ -741,7 +741,7 @@ struct GenericStruct64 { } #[derive(Clone, Default, Reflect)] -struct GenericStruct128 { +struct GenericStruct128 { field_0: T, field_1: T, field_2: T, diff --git a/crates/bevy_animation/src/animation_curves.rs b/crates/bevy_animation/src/animation_curves.rs index be68c9357658f..03a1e50bc1210 100644 --- a/crates/bevy_animation/src/animation_curves.rs +++ b/crates/bevy_animation/src/animation_curves.rs @@ -347,7 +347,7 @@ where impl AnimationCurve for AnimatableCurve where P: AnimatableProperty + Clone, - C: AnimationCompatibleCurve + Clone, + C: AnimationCompatibleCurve + Clone + Send + Sync, { fn clone_value(&self) -> Box { Box::new(self.clone()) @@ -469,7 +469,7 @@ struct WeightsCurveEvaluator { impl AnimationCurve for WeightsCurve where - C: IterableCurve + Debug + Clone + Reflectable, + C: IterableCurve + Debug + Clone + Reflectable + Send + Sync, { fn clone_value(&self) -> Box { Box::new(self.clone()) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index dacd9483ab5d2..f94534201ee47 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -620,7 +620,7 @@ impl App { /// See [`bevy_reflect::TypeRegistry::register_type_data`]. #[cfg(feature = "bevy_reflect")] pub fn register_type_data< - T: bevy_reflect::Reflect + bevy_reflect::TypePath, + T: bevy_reflect::Reflect + Send + Sync + bevy_reflect::TypePath, D: bevy_reflect::TypeData + bevy_reflect::FromType, >( &mut self, diff --git a/crates/bevy_app/src/sub_app.rs b/crates/bevy_app/src/sub_app.rs index ea51931b3507c..75018dab399ea 100644 --- a/crates/bevy_app/src/sub_app.rs +++ b/crates/bevy_app/src/sub_app.rs @@ -434,7 +434,7 @@ impl SubApp { /// See [`App::register_type_data`]. #[cfg(feature = "bevy_reflect")] pub fn register_type_data< - T: bevy_reflect::Reflect + bevy_reflect::TypePath, + T: bevy_reflect::Reflect + Send + Sync + bevy_reflect::TypePath, D: bevy_reflect::TypeData + bevy_reflect::FromType, >( &mut self, diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index f3f4cddeed989..669e2ae4f77ab 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -691,8 +691,9 @@ mod tests { "Inserting the asset should result in a strong count of 1" ); - let reflected: &dyn Reflect = &handle; - let _cloned_handle: Box = reflected.reflect_clone().unwrap(); + let reflected: &(dyn Reflect + Send + Sync) = &handle; + let _cloned_handle: Box = + reflected.reflect_clone().unwrap(); assert_eq!( Arc::strong_count(strong), @@ -700,7 +701,7 @@ mod tests { "Cloning the handle with reflect should increase the strong count to 2" ); - let dynamic_handle: Box = reflected.to_dynamic(); + let dynamic_handle: Box = reflected.to_dynamic(); assert_eq!( Arc::strong_count(strong), diff --git a/crates/bevy_asset/src/reflect.rs b/crates/bevy_asset/src/reflect.rs index 5c436c10610f0..b654f76290ccc 100644 --- a/crates/bevy_asset/src/reflect.rs +++ b/crates/bevy_asset/src/reflect.rs @@ -18,16 +18,17 @@ pub struct ReflectAsset { handle_type_id: TypeId, assets_resource_type_id: TypeId, - get: fn(&World, UntypedHandle) -> Option<&dyn Reflect>, + get: fn(&World, UntypedHandle) -> Option<&(dyn Reflect + Send + Sync)>, // SAFETY: // - may only be called with an [`UnsafeWorldCell`] which can be used to access the corresponding `Assets` resource mutably // - may only be used to access **at most one** access at once - get_unchecked_mut: unsafe fn(UnsafeWorldCell<'_>, UntypedHandle) -> Option<&mut dyn Reflect>, - add: fn(&mut World, &dyn PartialReflect) -> UntypedHandle, - insert: fn(&mut World, UntypedHandle, &dyn PartialReflect), + get_unchecked_mut: + unsafe fn(UnsafeWorldCell<'_>, UntypedHandle) -> Option<&mut (dyn Reflect + Send + Sync)>, + add: fn(&mut World, &(dyn PartialReflect + Send + Sync)) -> UntypedHandle, + insert: fn(&mut World, UntypedHandle, &(dyn PartialReflect + Send + Sync)), len: fn(&World) -> usize, ids: for<'w> fn(&'w World) -> Box + 'w>, - remove: fn(&mut World, UntypedHandle) -> Option>, + remove: fn(&mut World, UntypedHandle) -> Option>, } impl ReflectAsset { @@ -42,7 +43,11 @@ impl ReflectAsset { } /// Equivalent of [`Assets::get`] - pub fn get<'w>(&self, world: &'w World, handle: UntypedHandle) -> Option<&'w dyn Reflect> { + pub fn get<'w>( + &self, + world: &'w World, + handle: UntypedHandle, + ) -> Option<&'w (dyn Reflect + Send + Sync)> { (self.get)(world, handle) } @@ -51,7 +56,7 @@ impl ReflectAsset { &self, world: &'w mut World, handle: UntypedHandle, - ) -> Option<&'w mut dyn Reflect> { + ) -> Option<&'w mut (dyn Reflect + Send + Sync)> { // SAFETY: unique world access #[expect( unsafe_code, @@ -97,22 +102,35 @@ impl ReflectAsset { &self, world: UnsafeWorldCell<'w>, handle: UntypedHandle, - ) -> Option<&'w mut dyn Reflect> { + ) -> Option<&'w mut (dyn Reflect + Send + Sync)> { // SAFETY: requirements are deferred to the caller unsafe { (self.get_unchecked_mut)(world, handle) } } /// Equivalent of [`Assets::add`] - pub fn add(&self, world: &mut World, value: &dyn PartialReflect) -> UntypedHandle { + pub fn add( + &self, + world: &mut World, + value: &(dyn PartialReflect + Send + Sync), + ) -> UntypedHandle { (self.add)(world, value) } /// Equivalent of [`Assets::insert`] - pub fn insert(&self, world: &mut World, handle: UntypedHandle, value: &dyn PartialReflect) { + pub fn insert( + &self, + world: &mut World, + handle: UntypedHandle, + value: &(dyn PartialReflect + Send + Sync), + ) { (self.insert)(world, handle, value); } /// Equivalent of [`Assets::remove`] - pub fn remove(&self, world: &mut World, handle: UntypedHandle) -> Option> { + pub fn remove( + &self, + world: &mut World, + handle: UntypedHandle, + ) -> Option> { (self.remove)(world, handle) } @@ -140,7 +158,7 @@ impl FromType for ReflectAsset { get: |world, handle| { let assets = world.resource::>(); let asset = assets.get(&handle.typed_debug_checked()); - asset.map(|asset| asset as &dyn Reflect) + asset.map(|asset| asset as &(dyn Reflect + Send + Sync)) }, get_unchecked_mut: |world, handle| { // SAFETY: `get_unchecked_mut` must be called with `UnsafeWorldCell` having access to `Assets`, @@ -148,7 +166,7 @@ impl FromType for ReflectAsset { #[expect(unsafe_code, reason = "Uses `UnsafeWorldCell::get_resource_mut()`.")] let assets = unsafe { world.get_resource_mut::>().unwrap().into_inner() }; let asset = assets.get_mut(&handle.typed_debug_checked()); - asset.map(|asset| asset as &mut dyn Reflect) + asset.map(|asset| asset as &mut (dyn Reflect + Send + Sync)) }, add: |world, value| { let mut assets = world.resource_mut::>(); @@ -173,7 +191,7 @@ impl FromType for ReflectAsset { remove: |world, handle| { let mut assets = world.resource_mut::>(); let value = assets.remove(&handle.typed_debug_checked()); - value.map(|value| Box::new(value) as Box) + value.map(|value| Box::new(value) as Box) }, } } @@ -181,7 +199,7 @@ impl FromType for ReflectAsset { /// Reflect type data struct relating a [`Handle`] back to the `T` asset type. /// -/// Say you want to look up the asset values of a list of handles when you have access to their `&dyn Reflect` form. +/// Say you want to look up the asset values of a list of handles when you have access to their `&(dyn Reflect + Send + Sync)` form. /// Assets can be looked up in the world using [`ReflectAsset`], but how do you determine which [`ReflectAsset`] to use when /// only looking at the handle? [`ReflectHandle`] is stored in the type registry on each `Handle` type, so you can use [`ReflectHandle::asset_type_id`] to look up /// the [`ReflectAsset`] type data on the corresponding `T` asset type: @@ -194,7 +212,7 @@ impl FromType for ReflectAsset { /// /// # let world: &World = unimplemented!(); /// # let type_registry: TypeRegistry = unimplemented!(); -/// let handles: Vec<&dyn Reflect> = unimplemented!(); +/// let handles: Vec<&(dyn Reflect + Send + Sync)> = unimplemented!(); /// for handle in handles { /// let reflect_handle = type_registry.get_type_data::(handle.type_id()).unwrap(); /// let reflect_asset = type_registry.get_type_data::(reflect_handle.asset_type_id()).unwrap(); @@ -208,7 +226,7 @@ impl FromType for ReflectAsset { pub struct ReflectHandle { asset_type_id: TypeId, downcast_handle_untyped: fn(&dyn Any) -> Option, - typed: fn(UntypedHandle) -> Box, + typed: fn(UntypedHandle) -> Box, } impl ReflectHandle { /// The [`TypeId`] of the asset @@ -221,9 +239,9 @@ impl ReflectHandle { (self.downcast_handle_untyped)(handle) } - /// A way to go from a [`UntypedHandle`] to a [`Handle`] in a `Box`. + /// A way to go from a [`UntypedHandle`] to a [`Handle`] in a `Box`. /// Equivalent of [`UntypedHandle::typed`]. - pub fn typed(&self, handle: UntypedHandle) -> Box { + pub fn typed(&self, handle: UntypedHandle) -> Box { (self.typed)(handle) } } diff --git a/crates/bevy_color/Cargo.toml b/crates/bevy_color/Cargo.toml index 9b6d7d8cf6b8d..3212cc223f969 100644 --- a/crates/bevy_color/Cargo.toml +++ b/crates/bevy_color/Cargo.toml @@ -7,7 +7,7 @@ homepage = "https://bevyengine.org" repository = "https://github.com/bevyengine/bevy" license = "MIT OR Apache-2.0" keywords = ["bevy", "color"] -rust-version = "1.85.0" +rust-version = "1.86.0" [dependencies] bevy_math = { path = "../bevy_math", version = "0.16.0-dev", default-features = false, features = [ diff --git a/crates/bevy_dev_tools/src/picking_debug.rs b/crates/bevy_dev_tools/src/picking_debug.rs index f72b70fc881dd..90eb7475ac659 100644 --- a/crates/bevy_dev_tools/src/picking_debug.rs +++ b/crates/bevy_dev_tools/src/picking_debug.rs @@ -129,7 +129,7 @@ pub fn log_event_debug(mut events: EventReader( +pub fn log_pointer_event_debug( mut pointer_events: EventReader>, ) { for event in pointer_events.read() { @@ -138,7 +138,7 @@ pub fn log_pointer_event_debug( } /// Listens for pointer events of type `E` and logs them at "trace" level -pub fn log_pointer_event_trace( +pub fn log_pointer_event_trace( mut pointer_events: EventReader>, ) { for event in pointer_events.read() { diff --git a/crates/bevy_ecs/Cargo.toml b/crates/bevy_ecs/Cargo.toml index a8d817f43a1d3..64a0f18a07759 100644 --- a/crates/bevy_ecs/Cargo.toml +++ b/crates/bevy_ecs/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/bevyengine/bevy" license = "MIT OR Apache-2.0" keywords = ["ecs", "game", "bevy"] categories = ["game-engines", "data-structures"] -rust-version = "1.85.0" +rust-version = "1.86.0" [features] default = ["std", "bevy_reflect", "async_executor", "backtrace"] diff --git a/crates/bevy_ecs/src/entity/clone_entities.rs b/crates/bevy_ecs/src/entity/clone_entities.rs index b435ca0ebb5c5..1c37998fba2b8 100644 --- a/crates/bevy_ecs/src/entity/clone_entities.rs +++ b/crates/bevy_ecs/src/entity/clone_entities.rs @@ -43,7 +43,7 @@ impl<'a> SourceComponent<'a> { self.ptr } - /// Returns a reference to the component on the source entity as [`&dyn Reflect`](bevy_reflect::Reflect). + /// Returns a reference to the component on the source entity as [`&(dyn Reflect + Send + Sync)`](bevy_reflect::Reflect). /// /// Will return `None` if: /// - World does not have [`AppTypeRegistry`](`crate::reflect::AppTypeRegistry`). @@ -55,7 +55,7 @@ impl<'a> SourceComponent<'a> { pub fn read_reflect( &self, registry: &bevy_reflect::TypeRegistry, - ) -> Option<&dyn bevy_reflect::Reflect> { + ) -> Option<&(dyn bevy_reflect::Reflect + Send + Sync)> { let type_id = self.info.type_id()?; let reflect_from_ptr = registry.get_type_data::(type_id)?; if reflect_from_ptr.type_id() != type_id { @@ -219,7 +219,10 @@ impl<'a, 'b> ComponentCloneCtx<'a, 'b> { /// - Passed component's [`TypeId`] does not match source component [`TypeId`]. /// - Component has already been written once. #[cfg(feature = "bevy_reflect")] - pub fn write_target_component_reflect(&mut self, component: Box) { + pub fn write_target_component_reflect( + &mut self, + component: Box, + ) { if self.target_component_written { panic!("Trying to write component multiple times") } diff --git a/crates/bevy_ecs/src/reflect/bundle.rs b/crates/bevy_ecs/src/reflect/bundle.rs index ee02aff86e7fe..582b927799350 100644 --- a/crates/bevy_ecs/src/reflect/bundle.rs +++ b/crates/bevy_ecs/src/reflect/bundle.rs @@ -33,13 +33,13 @@ pub struct ReflectBundle(ReflectBundleFns); #[derive(Clone)] pub struct ReflectBundleFns { /// Function pointer implementing [`ReflectBundle::insert`]. - pub insert: fn(&mut EntityWorldMut, &dyn PartialReflect, &TypeRegistry), + pub insert: fn(&mut EntityWorldMut, &(dyn PartialReflect + Send + Sync), &TypeRegistry), /// Function pointer implementing [`ReflectBundle::apply`]. - pub apply: fn(EntityMut, &dyn PartialReflect, &TypeRegistry), + pub apply: fn(EntityMut, &(dyn PartialReflect + Send + Sync), &TypeRegistry), /// Function pointer implementing [`ReflectBundle::apply_or_insert_mapped`]. pub apply_or_insert_mapped: fn( &mut EntityWorldMut, - &dyn PartialReflect, + &(dyn PartialReflect + Send + Sync), &TypeRegistry, &mut dyn EntityMapper, RelationshipHookMode, @@ -47,7 +47,7 @@ pub struct ReflectBundleFns { /// Function pointer implementing [`ReflectBundle::remove`]. pub remove: fn(&mut EntityWorldMut), /// Function pointer implementing [`ReflectBundle::take`]. - pub take: fn(&mut EntityWorldMut) -> Option>, + pub take: fn(&mut EntityWorldMut) -> Option>, } impl ReflectBundleFns { @@ -66,7 +66,7 @@ impl ReflectBundle { pub fn insert( &self, entity: &mut EntityWorldMut, - bundle: &dyn PartialReflect, + bundle: &(dyn PartialReflect + Send + Sync), registry: &TypeRegistry, ) { (self.0.insert)(entity, bundle, registry); @@ -80,7 +80,7 @@ impl ReflectBundle { pub fn apply<'a>( &self, entity: impl Into>, - bundle: &dyn PartialReflect, + bundle: &(dyn PartialReflect + Send + Sync), registry: &TypeRegistry, ) { (self.0.apply)(entity.into(), bundle, registry); @@ -90,7 +90,7 @@ impl ReflectBundle { pub fn apply_or_insert_mapped( &self, entity: &mut EntityWorldMut, - bundle: &dyn PartialReflect, + bundle: &(dyn PartialReflect + Send + Sync), registry: &TypeRegistry, mapper: &mut dyn EntityMapper, relationship_hook_mode: RelationshipHookMode, @@ -108,7 +108,7 @@ impl ReflectBundle { /// /// **Note:** If the entity does not have every component in the bundle, this method will not remove any of them. #[must_use] - pub fn take(&self, entity: &mut EntityWorldMut) -> Option> { + pub fn take(&self, entity: &mut EntityWorldMut) -> Option> { (self.0.take)(entity) } @@ -147,7 +147,9 @@ impl ReflectBundle { } } -impl FromType for ReflectBundle { +impl FromType + for ReflectBundle +{ fn from_type() -> Self { ReflectBundle(ReflectBundleFns { insert: |entity, reflected_bundle, registry| { @@ -232,7 +234,11 @@ impl FromType for Refl } } -fn apply_field(entity: &mut EntityMut, field: &dyn PartialReflect, registry: &TypeRegistry) { +fn apply_field( + entity: &mut EntityMut, + field: &(dyn PartialReflect + Send + Sync), + registry: &TypeRegistry, +) { let Some(type_id) = field.try_as_reflect().map(Any::type_id) else { panic!( "`{}` did not implement `Reflect`", @@ -253,7 +259,7 @@ fn apply_field(entity: &mut EntityMut, field: &dyn PartialReflect, registry: &Ty fn apply_or_insert_field_mapped( entity: &mut EntityWorldMut, - field: &dyn PartialReflect, + field: &(dyn PartialReflect + Send + Sync), registry: &TypeRegistry, mapper: &mut dyn EntityMapper, relationship_hook_mode: RelationshipHookMode, diff --git a/crates/bevy_ecs/src/reflect/component.rs b/crates/bevy_ecs/src/reflect/component.rs index 893e9b13fa8e3..7d3cf0dda1ed7 100644 --- a/crates/bevy_ecs/src/reflect/component.rs +++ b/crates/bevy_ecs/src/reflect/component.rs @@ -39,7 +39,7 @@ //! In those functions, we call generic methods on [`World`] and [`EntityWorldMut`]. //! //! The result is a `ReflectComponent` completely independent of `C`, yet capable -//! of using generic ECS methods such as `entity.get::()` to get `&dyn Reflect` +//! of using generic ECS methods such as `entity.get::()` to get `&(dyn Reflect + Send + Sync)` //! with underlying type `C`, without the `C` appearing in the type signature. //! //! ## A note on code generation @@ -102,13 +102,13 @@ pub struct ReflectComponent(ReflectComponentFns); #[derive(Clone)] pub struct ReflectComponentFns { /// Function pointer implementing [`ReflectComponent::insert()`]. - pub insert: fn(&mut EntityWorldMut, &dyn PartialReflect, &TypeRegistry), + pub insert: fn(&mut EntityWorldMut, &(dyn PartialReflect + Send + Sync), &TypeRegistry), /// Function pointer implementing [`ReflectComponent::apply()`]. - pub apply: fn(EntityMut, &dyn PartialReflect), + pub apply: fn(EntityMut, &(dyn PartialReflect + Send + Sync)), /// Function pointer implementing [`ReflectComponent::apply_or_insert_mapped()`]. pub apply_or_insert_mapped: fn( &mut EntityWorldMut, - &dyn PartialReflect, + &(dyn PartialReflect + Send + Sync), &TypeRegistry, &mut dyn EntityMapper, RelationshipHookMode, @@ -118,16 +118,17 @@ pub struct ReflectComponentFns { /// Function pointer implementing [`ReflectComponent::contains()`]. pub contains: fn(FilteredEntityRef) -> bool, /// Function pointer implementing [`ReflectComponent::reflect()`]. - pub reflect: fn(FilteredEntityRef) -> Option<&dyn Reflect>, + pub reflect: fn(FilteredEntityRef) -> Option<&(dyn Reflect + Send + Sync)>, /// Function pointer implementing [`ReflectComponent::reflect_mut()`]. - pub reflect_mut: fn(FilteredEntityMut) -> Option>, + pub reflect_mut: fn(FilteredEntityMut) -> Option>, /// Function pointer implementing [`ReflectComponent::map_entities()`]. - pub map_entities: fn(&mut dyn Reflect, &mut dyn EntityMapper), + pub map_entities: fn(&mut (dyn Reflect + Send + Sync), &mut dyn EntityMapper), /// Function pointer implementing [`ReflectComponent::reflect_unchecked_mut()`]. /// /// # Safety /// The function may only be called with an [`UnsafeEntityCell`] that can be used to mutably access the relevant component on the given entity. - pub reflect_unchecked_mut: unsafe fn(UnsafeEntityCell<'_>) -> Option>, + pub reflect_unchecked_mut: + unsafe fn(UnsafeEntityCell<'_>) -> Option>, /// Function pointer implementing [`ReflectComponent::copy()`]. pub copy: fn(&World, &mut World, Entity, Entity, &TypeRegistry), /// Function pointer implementing [`ReflectComponent::register_component()`]. @@ -150,7 +151,7 @@ impl ReflectComponent { pub fn insert( &self, entity: &mut EntityWorldMut, - component: &dyn PartialReflect, + component: &(dyn PartialReflect + Send + Sync), registry: &TypeRegistry, ) { (self.0.insert)(entity, component, registry); @@ -163,7 +164,11 @@ impl ReflectComponent { /// Panics if there is no [`Component`] of the given type. /// /// Will also panic if [`Component`] is immutable. - pub fn apply<'a>(&self, entity: impl Into>, component: &dyn PartialReflect) { + pub fn apply<'a>( + &self, + entity: impl Into>, + component: &(dyn PartialReflect + Send + Sync), + ) { (self.0.apply)(entity.into(), component); } @@ -175,7 +180,7 @@ impl ReflectComponent { pub fn apply_or_insert_mapped( &self, entity: &mut EntityWorldMut, - component: &dyn PartialReflect, + component: &(dyn PartialReflect + Send + Sync), registry: &TypeRegistry, map: &mut dyn EntityMapper, relationship_hook_mode: RelationshipHookMode, @@ -194,7 +199,10 @@ impl ReflectComponent { } /// Gets the value of this [`Component`] type from the entity as a reflected reference. - pub fn reflect<'a>(&self, entity: impl Into>) -> Option<&'a dyn Reflect> { + pub fn reflect<'a>( + &self, + entity: impl Into>, + ) -> Option<&'a (dyn Reflect + Send + Sync)> { (self.0.reflect)(entity.into()) } @@ -206,7 +214,7 @@ impl ReflectComponent { pub fn reflect_mut<'a>( &self, entity: impl Into>, - ) -> Option> { + ) -> Option> { (self.0.reflect_mut)(entity.into()) } @@ -222,7 +230,7 @@ impl ReflectComponent { pub unsafe fn reflect_unchecked_mut<'a>( &self, entity: UnsafeEntityCell<'a>, - ) -> Option> { + ) -> Option> { // SAFETY: safety requirements deferred to caller unsafe { (self.0.reflect_unchecked_mut)(entity) } } @@ -290,12 +298,16 @@ impl ReflectComponent { } /// Calls a dynamic version of [`Component::map_entities`]. - pub fn map_entities(&self, component: &mut dyn Reflect, func: &mut dyn EntityMapper) { + pub fn map_entities( + &self, + component: &mut (dyn Reflect + Send + Sync), + func: &mut dyn EntityMapper, + ) { (self.0.map_entities)(component, func); } } -impl FromType for ReflectComponent { +impl FromType for ReflectComponent { fn from_type() -> Self { // TODO: Currently we panic if a component is immutable and you use // reflection to mutate it. Perhaps the mutation methods should be fallible? @@ -354,7 +366,7 @@ impl FromType for ReflectComponent { .entity_mut(destination_entity) .insert(destination_component); }, - reflect: |entity| entity.get::().map(|c| c as &dyn Reflect), + reflect: |entity| entity.get::().map(|c| c as &(dyn Reflect + Send + Sync)), reflect_mut: |entity| { if !C::Mutability::MUTABLE { let name = ShortName::of::(); @@ -365,7 +377,7 @@ impl FromType for ReflectComponent { unsafe { entity .into_mut_assume_mutable::() - .map(|c| c.map_unchanged(|value| value as &mut dyn Reflect)) + .map(|c| c.map_unchanged(|value| value as &mut (dyn Reflect + Send + Sync))) } }, reflect_unchecked_mut: |entity| { @@ -378,12 +390,13 @@ impl FromType for ReflectComponent { // `reflect_unchecked_mut` which must be called with an UnsafeEntityCell with access to the component `C` on the `entity` // guard ensures `C` is a mutable component let c = unsafe { entity.get_mut_assume_mutable::() }; - c.map(|c| c.map_unchanged(|value| value as &mut dyn Reflect)) + c.map(|c| c.map_unchanged(|value| value as &mut (dyn Reflect + Send + Sync))) }, register_component: |world: &mut World| -> ComponentId { world.register_component::() }, - map_entities: |reflect: &mut dyn Reflect, mut mapper: &mut dyn EntityMapper| { + map_entities: |reflect: &mut (dyn Reflect + Send + Sync), + mut mapper: &mut dyn EntityMapper| { let component = reflect.downcast_mut::().unwrap(); Component::map_entities(component, &mut mapper); }, diff --git a/crates/bevy_ecs/src/reflect/entity_commands.rs b/crates/bevy_ecs/src/reflect/entity_commands.rs index 20c5e16c6ddc7..772caed64d0fd 100644 --- a/crates/bevy_ecs/src/reflect/entity_commands.rs +++ b/crates/bevy_ecs/src/reflect/entity_commands.rs @@ -42,7 +42,7 @@ pub trait ReflectCommandExt { /// // A resource that can hold any component that implements reflect as a boxed reflect component /// #[derive(Resource)] /// struct Prefab { - /// data: Box, + /// data: Box, /// } /// #[derive(Component, Reflect, Default)] /// #[reflect(Component)] @@ -64,9 +64,9 @@ pub trait ReflectCommandExt { /// mut prefab: ResMut /// ) { /// // Create a set of new boxed reflect components to use - /// let boxed_reflect_component_a: Box = Box::new(ComponentA(916)); - /// let boxed_reflect_component_b: Box = Box::new(ComponentB("NineSixteen".to_string())); - /// let boxed_reflect_bundle_a: Box = Box::new(BundleA { + /// let boxed_reflect_component_a: Box = Box::new(ComponentA(916)); + /// let boxed_reflect_component_b: Box = Box::new(ComponentB("NineSixteen".to_string())); + /// let boxed_reflect_bundle_a: Box = Box::new(BundleA { /// a: ComponentA(24), /// b: ComponentB("Twenty-Four".to_string()), /// }); @@ -85,7 +85,7 @@ pub trait ReflectCommandExt { /// .insert_reflect(prefab.data.reflect_clone().unwrap().into_partial_reflect()); /// } /// ``` - fn insert_reflect(&mut self, component: Box) -> &mut Self; + fn insert_reflect(&mut self, component: Box) -> &mut Self; /// Same as [`insert_reflect`](ReflectCommandExt::insert_reflect), but using the `T` resource as type registry instead of /// `AppTypeRegistry`. @@ -99,7 +99,7 @@ pub trait ReflectCommandExt { /// - The given [`Resource`] is removed from the [`World`] before the command is applied. fn insert_reflect_with_registry>( &mut self, - component: Box, + component: Box, ) -> &mut Self; /// Removes from the entity the component or bundle with the given type name registered in [`AppTypeRegistry`]. @@ -132,7 +132,7 @@ pub trait ReflectCommandExt { /// #[derive(Resource)] /// struct Prefab{ /// entity: Entity, - /// data: Box, + /// data: Box, /// } /// #[derive(Component, Reflect, Default)] /// #[reflect(Component)] @@ -169,7 +169,7 @@ pub trait ReflectCommandExt { } impl ReflectCommandExt for EntityCommands<'_> { - fn insert_reflect(&mut self, component: Box) -> &mut Self { + fn insert_reflect(&mut self, component: Box) -> &mut Self { self.queue(move |mut entity: EntityWorldMut| { entity.insert_reflect(component); }) @@ -177,7 +177,7 @@ impl ReflectCommandExt for EntityCommands<'_> { fn insert_reflect_with_registry>( &mut self, - component: Box, + component: Box, ) -> &mut Self { self.queue(move |mut entity: EntityWorldMut| { entity.insert_reflect_with_registry::(component); @@ -220,7 +220,10 @@ impl<'w> EntityWorldMut<'w> { /// /// Prefer to use the typed [`EntityWorldMut::insert`] if possible. Adding a reflected component /// is much slower. - pub fn insert_reflect(&mut self, component: Box) -> &mut Self { + pub fn insert_reflect( + &mut self, + component: Box, + ) -> &mut Self { self.assert_not_despawned(); let entity_id = self.id(); self.world_scope(|world| { @@ -248,7 +251,7 @@ impl<'w> EntityWorldMut<'w> { /// - If the given [`Resource`] is not present in the [`World`]. pub fn insert_reflect_with_registry>( &mut self, - component: Box, + component: Box, ) -> &mut Self { self.assert_not_despawned(); let entity_id = self.id(); @@ -342,7 +345,7 @@ fn insert_reflect_with_registry_ref( world: &mut World, entity: Entity, type_registry: &TypeRegistry, - component: Box, + component: Box, ) { let type_info = component .get_represented_type_info() @@ -444,7 +447,8 @@ mod tests { let entity2 = commands.spawn_empty().id(); let entity3 = commands.spawn_empty().id(); - let boxed_reflect_component_a = Box::new(ComponentA(916)) as Box; + let boxed_reflect_component_a = + Box::new(ComponentA(916)) as Box; let boxed_reflect_component_a_clone = boxed_reflect_component_a.reflect_clone().unwrap(); let boxed_reflect_component_a_dynamic = boxed_reflect_component_a.to_dynamic(); @@ -488,7 +492,8 @@ mod tests { let entity = commands.spawn_empty().id(); - let boxed_reflect_component_a = Box::new(ComponentA(916)) as Box; + let boxed_reflect_component_a = + Box::new(ComponentA(916)) as Box; commands .entity(entity) @@ -518,7 +523,7 @@ mod tests { let entity = commands.spawn(ComponentA(0)).id(); - let boxed_reflect_component_a = Box::new(ComponentA(916)) as Box; + let boxed_reflect_component_a = Box::new(ComponentA(916)) as Box; commands .entity(entity) @@ -547,7 +552,7 @@ mod tests { let entity = commands.spawn(ComponentA(0)).id(); - let boxed_reflect_component_a = Box::new(ComponentA(916)) as Box; + let boxed_reflect_component_a = Box::new(ComponentA(916)) as Box; commands .entity(entity) @@ -578,7 +583,7 @@ mod tests { let bundle = Box::new(BundleA { a: ComponentA(31), b: ComponentB(20), - }) as Box; + }) as Box; commands.entity(entity).insert_reflect(bundle); system_state.apply(&mut world); @@ -608,7 +613,7 @@ mod tests { let bundle = Box::new(BundleA { a: ComponentA(31), b: ComponentB(20), - }) as Box; + }) as Box; commands .entity(entity) @@ -644,7 +649,7 @@ mod tests { let boxed_reflect_bundle_a = Box::new(BundleA { a: ComponentA(1), b: ComponentB(23), - }) as Box; + }) as Box; commands .entity(entity) @@ -682,7 +687,7 @@ mod tests { let boxed_reflect_bundle_a = Box::new(BundleA { a: ComponentA(1), b: ComponentB(23), - }) as Box; + }) as Box; commands .entity(entity) diff --git a/crates/bevy_ecs/src/reflect/from_world.rs b/crates/bevy_ecs/src/reflect/from_world.rs index c4f5912ff4b5f..7590a69d4e830 100644 --- a/crates/bevy_ecs/src/reflect/from_world.rs +++ b/crates/bevy_ecs/src/reflect/from_world.rs @@ -22,7 +22,7 @@ pub struct ReflectFromWorld(ReflectFromWorldFns); #[derive(Clone)] pub struct ReflectFromWorldFns { /// Function pointer implementing [`ReflectFromWorld::from_world()`]. - pub from_world: fn(&mut World) -> Box, + pub from_world: fn(&mut World) -> Box, } impl ReflectFromWorldFns { @@ -31,14 +31,14 @@ impl ReflectFromWorldFns { /// /// This is useful if you want to start with the default implementation before overriding some /// of the functions to create a custom implementation. - pub fn new() -> Self { + pub fn new() -> Self { >::from_type().0 } } impl ReflectFromWorld { /// Constructs default reflected [`FromWorld`] from world using [`from_world()`](FromWorld::from_world). - pub fn from_world(&self, world: &mut World) -> Box { + pub fn from_world(&self, world: &mut World) -> Box { (self.0.from_world)(world) } @@ -78,7 +78,7 @@ impl ReflectFromWorld { } } -impl FromType for ReflectFromWorld { +impl FromType for ReflectFromWorld { fn from_type() -> Self { ReflectFromWorld(ReflectFromWorldFns { from_world: |world| Box::new(B::from_world(world)), diff --git a/crates/bevy_ecs/src/reflect/map_entities.rs b/crates/bevy_ecs/src/reflect/map_entities.rs index 04fc25579906d..552500e35a573 100644 --- a/crates/bevy_ecs/src/reflect/map_entities.rs +++ b/crates/bevy_ecs/src/reflect/map_entities.rs @@ -12,7 +12,7 @@ use bevy_reflect::{FromReflect, FromType, PartialReflect}; /// [`EntityMapper`]: crate::entity::EntityMapper #[derive(Clone)] pub struct ReflectMapEntities { - map_entities: fn(&mut dyn PartialReflect, &mut dyn EntityMapper), + map_entities: fn(&mut (dyn PartialReflect + Send + Sync), &mut dyn EntityMapper), } impl ReflectMapEntities { @@ -20,12 +20,16 @@ impl ReflectMapEntities { /// /// # Panics /// Panics if the type of the reflected value doesn't match. - pub fn map_entities(&self, reflected: &mut dyn PartialReflect, mapper: &mut dyn EntityMapper) { + pub fn map_entities( + &self, + reflected: &mut (dyn PartialReflect + Send + Sync), + mapper: &mut dyn EntityMapper, + ) { (self.map_entities)(reflected, mapper); } } -impl FromType for ReflectMapEntities { +impl FromType for ReflectMapEntities { fn from_type() -> Self { ReflectMapEntities { map_entities: |reflected, mut mapper| { diff --git a/crates/bevy_ecs/src/reflect/mod.rs b/crates/bevy_ecs/src/reflect/mod.rs index b630f587197d7..1bf98e40dd98f 100644 --- a/crates/bevy_ecs/src/reflect/mod.rs +++ b/crates/bevy_ecs/src/reflect/mod.rs @@ -72,7 +72,7 @@ impl DerefMut for AppFunctionRegistry { } } -/// Creates a `T` from a `&dyn PartialReflect`. +/// Creates a `T` from a ` &(dyn Reflect + Send + Sync)`. /// /// This will try the following strategies, in this order: /// @@ -84,12 +84,12 @@ impl DerefMut for AppFunctionRegistry { /// /// # Panics /// -/// If any strategy produces a `Box` that doesn't store a value of type `T` +/// If any strategy produces a `Box` that doesn't store a value of type `T` /// this method will panic. /// /// If none of the strategies succeed, this method will panic. -pub fn from_reflect_with_fallback( - reflected: &dyn PartialReflect, +pub fn from_reflect_with_fallback( + reflected: &(dyn PartialReflect + Send + Sync), world: &mut World, registry: &TypeRegistry, ) -> T { diff --git a/crates/bevy_ecs/src/reflect/resource.rs b/crates/bevy_ecs/src/reflect/resource.rs index 60cf7bc609169..95f8f76117cb4 100644 --- a/crates/bevy_ecs/src/reflect/resource.rs +++ b/crates/bevy_ecs/src/reflect/resource.rs @@ -47,25 +47,28 @@ pub struct ReflectResource(ReflectResourceFns); #[derive(Clone)] pub struct ReflectResourceFns { /// Function pointer implementing [`ReflectResource::insert()`]. - pub insert: fn(&mut World, &dyn PartialReflect, &TypeRegistry), + pub insert: fn(&mut World, &(dyn PartialReflect + Send + Sync), &TypeRegistry), /// Function pointer implementing [`ReflectResource::apply()`]. - pub apply: fn(&mut World, &dyn PartialReflect), + pub apply: fn(&mut World, &(dyn PartialReflect + Send + Sync)), /// Function pointer implementing [`ReflectResource::apply_or_insert()`]. - pub apply_or_insert: fn(&mut World, &dyn PartialReflect, &TypeRegistry), + pub apply_or_insert: fn(&mut World, &(dyn PartialReflect + Send + Sync), &TypeRegistry), /// Function pointer implementing [`ReflectResource::remove()`]. pub remove: fn(&mut World), /// Function pointer implementing [`ReflectResource::reflect()`]. - pub reflect: - for<'w> fn(FilteredResources<'w, '_>) -> Result<&'w dyn Reflect, ResourceFetchError>, + pub reflect: for<'w> fn( + FilteredResources<'w, '_>, + ) -> Result<&'w (dyn Reflect + Send + Sync), ResourceFetchError>, /// Function pointer implementing [`ReflectResource::reflect_mut()`]. pub reflect_mut: for<'w> fn( FilteredResourcesMut<'w, '_>, - ) -> Result, ResourceFetchError>, + ) + -> Result, ResourceFetchError>, /// Function pointer implementing [`ReflectResource::reflect_unchecked_mut()`]. /// /// # Safety /// The function may only be called with an [`UnsafeWorldCell`] that can be used to mutably access the relevant resource. - pub reflect_unchecked_mut: unsafe fn(UnsafeWorldCell<'_>) -> Option>, + pub reflect_unchecked_mut: + unsafe fn(UnsafeWorldCell<'_>) -> Option>, /// Function pointer implementing [`ReflectResource::copy()`]. pub copy: fn(&World, &mut World, &TypeRegistry), /// Function pointer implementing [`ReflectResource::register_resource()`]. @@ -88,7 +91,7 @@ impl ReflectResource { pub fn insert( &self, world: &mut World, - resource: &dyn PartialReflect, + resource: &(dyn PartialReflect + Send + Sync), registry: &TypeRegistry, ) { (self.0.insert)(world, resource, registry); @@ -99,7 +102,7 @@ impl ReflectResource { /// # Panics /// /// Panics if there is no [`Resource`] of the given type. - pub fn apply(&self, world: &mut World, resource: &dyn PartialReflect) { + pub fn apply(&self, world: &mut World, resource: &(dyn PartialReflect + Send + Sync)) { (self.0.apply)(world, resource); } @@ -107,7 +110,7 @@ impl ReflectResource { pub fn apply_or_insert( &self, world: &mut World, - resource: &dyn PartialReflect, + resource: &(dyn PartialReflect + Send + Sync), registry: &TypeRegistry, ) { (self.0.apply_or_insert)(world, resource, registry); @@ -124,7 +127,7 @@ impl ReflectResource { pub fn reflect<'w, 's>( &self, resources: impl Into>, - ) -> Result<&'w dyn Reflect, ResourceFetchError> { + ) -> Result<&'w (dyn Reflect + Send + Sync), ResourceFetchError> { (self.0.reflect)(resources.into()) } @@ -134,7 +137,7 @@ impl ReflectResource { pub fn reflect_mut<'w, 's>( &self, resources: impl Into>, - ) -> Result, ResourceFetchError> { + ) -> Result, ResourceFetchError> { (self.0.reflect_mut)(resources.into()) } @@ -146,7 +149,7 @@ impl ReflectResource { pub unsafe fn reflect_unchecked_mut<'w>( &self, world: UnsafeWorldCell<'w>, - ) -> Option> { + ) -> Option> { // SAFETY: caller promises to uphold uniqueness guarantees unsafe { (self.0.reflect_unchecked_mut)(world) } } @@ -229,17 +232,21 @@ impl FromType for ReflectResource { remove: |world| { world.remove_resource::(); }, - reflect: |world| world.get::().map(|res| res.into_inner() as &dyn Reflect), + reflect: |world| { + world + .get::() + .map(|res| res.into_inner() as &(dyn Reflect + Send + Sync)) + }, reflect_mut: |world| { world .into_mut::() - .map(|res| res.map_unchanged(|value| value as &mut dyn Reflect)) + .map(|res| res.map_unchanged(|value| value as &mut (dyn Reflect + Send + Sync))) }, reflect_unchecked_mut: |world| { // SAFETY: all usages of `reflect_unchecked_mut` guarantee that there is either a single mutable // reference or multiple immutable ones alive at any given point let res = unsafe { world.get_resource_mut::() }; - res.map(|res| res.map_unchanged(|value| value as &mut dyn Reflect)) + res.map(|res| res.map_unchanged(|value| value as &mut (dyn Reflect + Send + Sync))) }, copy: |source_world, destination_world, registry| { let source_resource = source_world.resource::(); diff --git a/crates/bevy_ecs/src/world/reflect.rs b/crates/bevy_ecs/src/world/reflect.rs index fdd8b28142576..1b30f3865713b 100644 --- a/crates/bevy_ecs/src/world/reflect.rs +++ b/crates/bevy_ecs/src/world/reflect.rs @@ -48,7 +48,7 @@ impl World { /// let entity = world.spawn(MyComponent).id(); /// /// // retrieve a reflected reference to the entity's `MyComponent` - /// let comp_reflected: &dyn Reflect = world.get_reflect(entity, TypeId::of::()).unwrap(); + /// let comp_reflected: &(dyn Reflect + Send + Sync) = world.get_reflect(entity, TypeId::of::()).unwrap(); /// /// // make sure we got the expected type /// assert!(comp_reflected.is::()); @@ -69,7 +69,7 @@ impl World { &self, entity: Entity, type_id: TypeId, - ) -> Result<&dyn Reflect, GetComponentReflectError> { + ) -> Result<&(dyn Reflect + Send + Sync), GetComponentReflectError> { let Some(component_id) = self.components().get_id(type_id) else { return Err(GetComponentReflectError::NoCorrespondingComponentId( type_id, @@ -144,7 +144,7 @@ impl World { &mut self, entity: Entity, type_id: TypeId, - ) -> Result, GetComponentReflectError> { + ) -> Result, GetComponentReflectError> { // little clone() + read() dance so we a) don't keep a borrow of `self` and b) don't drop a // temporary (from read()) too early. let Some(app_type_registry) = self.get_resource::().cloned() else { diff --git a/crates/bevy_gizmos/src/config.rs b/crates/bevy_gizmos/src/config.rs index 973fa1cf0fbce..dd9fa2781b7d4 100644 --- a/crates/bevy_gizmos/src/config.rs +++ b/crates/bevy_gizmos/src/config.rs @@ -81,7 +81,7 @@ impl Hash for GizmoLineStyle { /// Here you can store additional configuration for you gizmo group not covered by [`GizmoConfig`] /// /// Make sure to derive [`Default`] + [`Reflect`] and register in the app using `app.init_gizmo_group::()` -pub trait GizmoConfigGroup: Reflect + TypePath + Default {} +pub trait GizmoConfigGroup: Reflect + Send + Sync + TypePath + Default {} /// The default gizmo config group. #[derive(Default, Reflect, GizmoConfigGroup)] @@ -102,12 +102,15 @@ pub struct ErasedGizmoConfigGroup; pub struct GizmoConfigStore { // INVARIANT: must map TypeId::of::() to correct type T #[reflect(ignore)] - store: TypeIdMap<(GizmoConfig, Box)>, + store: TypeIdMap<(GizmoConfig, Box)>, } impl GizmoConfigStore { /// Returns [`GizmoConfig`] and [`GizmoConfigGroup`] associated with [`TypeId`] of a [`GizmoConfigGroup`] - pub fn get_config_dyn(&self, config_type_id: &TypeId) -> Option<(&GizmoConfig, &dyn Reflect)> { + pub fn get_config_dyn( + &self, + config_type_id: &TypeId, + ) -> Option<(&GizmoConfig, &(dyn Reflect + Send + Sync))> { let (config, ext) = self.store.get(config_type_id)?; Some((config, ext.deref())) } @@ -117,7 +120,7 @@ impl GizmoConfigStore { let Some((config, ext)) = self.get_config_dyn(&TypeId::of::()) else { panic!("Requested config {} does not exist in `GizmoConfigStore`! Did you forget to add it using `app.init_gizmo_group()`?", T::type_path()); }; - // hash map invariant guarantees that &dyn Reflect is of correct type T + // hash map invariant guarantees that &(dyn Reflect + Send + Sync) is of correct type T let ext = ext.as_any().downcast_ref().unwrap(); (config, ext) } @@ -126,7 +129,7 @@ impl GizmoConfigStore { pub fn get_config_mut_dyn( &mut self, config_type_id: &TypeId, - ) -> Option<(&mut GizmoConfig, &mut dyn Reflect)> { + ) -> Option<(&mut GizmoConfig, &mut (dyn Reflect + Send + Sync))> { let (config, ext) = self.store.get_mut(config_type_id)?; Some((config, ext.deref_mut())) } @@ -136,13 +139,15 @@ impl GizmoConfigStore { let Some((config, ext)) = self.get_config_mut_dyn(&TypeId::of::()) else { panic!("Requested config {} does not exist in `GizmoConfigStore`! Did you forget to add it using `app.init_gizmo_group()`?", T::type_path()); }; - // hash map invariant guarantees that &dyn Reflect is of correct type T + // hash map invariant guarantees that &(dyn Reflect + Send + Sync) is of correct type T let ext = ext.as_any_mut().downcast_mut().unwrap(); (config, ext) } /// Returns an iterator over all [`GizmoConfig`]s. - pub fn iter(&self) -> impl Iterator + '_ { + pub fn iter( + &self, + ) -> impl Iterator + '_ { self.store .iter() .map(|(id, (config, ext))| (id, config, ext.deref())) @@ -151,7 +156,8 @@ impl GizmoConfigStore { /// Returns an iterator over all [`GizmoConfig`]s, by mutable reference. pub fn iter_mut( &mut self, - ) -> impl Iterator + '_ { + ) -> impl Iterator + '_ + { self.store .iter_mut() .map(|(id, (config, ext))| (id, config, ext.deref_mut())) @@ -159,7 +165,7 @@ impl GizmoConfigStore { /// Inserts [`GizmoConfig`] and [`GizmoConfigGroup`] replacing old values pub fn insert(&mut self, config: GizmoConfig, ext_config: T) { - // INVARIANT: hash map must correctly map TypeId::of::() to &dyn Reflect of type T + // INVARIANT: hash map must correctly map TypeId::of::() to &(dyn Reflect + Send + Sync) of type T self.store .insert(TypeId::of::(), (config, Box::new(ext_config))); } diff --git a/crates/bevy_input_focus/Cargo.toml b/crates/bevy_input_focus/Cargo.toml index 0b2ca538307e7..ff1d36956eff3 100644 --- a/crates/bevy_input_focus/Cargo.toml +++ b/crates/bevy_input_focus/Cargo.toml @@ -7,7 +7,7 @@ homepage = "https://bevyengine.org" repository = "https://github.com/bevyengine/bevy" license = "MIT OR Apache-2.0" keywords = ["bevy"] -rust-version = "1.85.0" +rust-version = "1.86.0" [features] default = ["std", "bevy_reflect", "bevy_ecs/async_executor"] diff --git a/crates/bevy_math/Cargo.toml b/crates/bevy_math/Cargo.toml index 7aae1ec74be45..87fe877955df1 100644 --- a/crates/bevy_math/Cargo.toml +++ b/crates/bevy_math/Cargo.toml @@ -7,7 +7,7 @@ homepage = "https://bevyengine.org" repository = "https://github.com/bevyengine/bevy" license = "MIT OR Apache-2.0" keywords = ["bevy"] -rust-version = "1.85.0" +rust-version = "1.86.0" [dependencies] glam = { version = "0.29.3", default-features = false, features = ["bytemuck"] } diff --git a/crates/bevy_math/src/curve/sample_curves.rs b/crates/bevy_math/src/curve/sample_curves.rs index f0fa928abba57..49256614550b7 100644 --- a/crates/bevy_math/src/curve/sample_curves.rs +++ b/crates/bevy_math/src/curve/sample_curves.rs @@ -384,9 +384,12 @@ mod tests { let samples = [0.0, 1.0, 2.0]; - let _: Box = Box::new(SampleCurve::new(Interval::UNIT, samples, foo).unwrap()); - let _: Box = Box::new(SampleCurve::new(Interval::UNIT, samples, bar).unwrap()); - let _: Box = Box::new(SampleCurve::new(Interval::UNIT, samples, baz).unwrap()); + let _: Box = + Box::new(SampleCurve::new(Interval::UNIT, samples, foo).unwrap()); + let _: Box = + Box::new(SampleCurve::new(Interval::UNIT, samples, bar).unwrap()); + let _: Box = + Box::new(SampleCurve::new(Interval::UNIT, samples, baz).unwrap()); } #[test] @@ -399,8 +402,11 @@ mod tests { let keyframes = [(0.0, 1.0), (1.0, 0.0), (2.0, -1.0)]; - let _: Box = Box::new(UnevenSampleCurve::new(keyframes, foo).unwrap()); - let _: Box = Box::new(UnevenSampleCurve::new(keyframes, bar).unwrap()); - let _: Box = Box::new(UnevenSampleCurve::new(keyframes, baz).unwrap()); + let _: Box = + Box::new(UnevenSampleCurve::new(keyframes, foo).unwrap()); + let _: Box = + Box::new(UnevenSampleCurve::new(keyframes, bar).unwrap()); + let _: Box = + Box::new(UnevenSampleCurve::new(keyframes, baz).unwrap()); } } diff --git a/crates/bevy_mikktspace/Cargo.toml b/crates/bevy_mikktspace/Cargo.toml index fbca931fe2a42..a03f64642d3e4 100644 --- a/crates/bevy_mikktspace/Cargo.toml +++ b/crates/bevy_mikktspace/Cargo.toml @@ -13,7 +13,7 @@ homepage = "https://bevyengine.org" repository = "https://github.com/bevyengine/bevy" license = "Zlib AND (MIT OR Apache-2.0)" keywords = ["bevy", "3D", "graphics", "algorithm", "tangent"] -rust-version = "1.85.0" +rust-version = "1.86.0" [features] default = ["std"] diff --git a/crates/bevy_picking/src/events.rs b/crates/bevy_picking/src/events.rs index ec2c49274b80e..65933522adc86 100644 --- a/crates/bevy_picking/src/events.rs +++ b/crates/bevy_picking/src/events.rs @@ -85,7 +85,7 @@ pub struct PointerTraversal { impl Traversal> for PointerTraversal where - E: Debug + Clone + Reflect, + E: Debug + Clone + Reflect + Send + Sync, { fn traverse(item: Self::Item<'_>, pointer: &Pointer) -> Option { let PointerTraversalItem { child_of, window } = item; @@ -108,14 +108,14 @@ where impl Event for Pointer where - E: Debug + Clone + Reflect, + E: Debug + Clone + Reflect + Send + Sync, { type Traversal = PointerTraversal; const AUTO_PROPAGATE: bool = true; } -impl core::fmt::Display for Pointer { +impl core::fmt::Display for Pointer { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_fmt(format_args!( "{:?}, {:.1?}, {:.1?}", @@ -124,7 +124,7 @@ impl core::fmt::Display for Pointer { } } -impl core::ops::Deref for Pointer { +impl core::ops::Deref for Pointer { type Target = E; fn deref(&self) -> &Self::Target { @@ -132,7 +132,7 @@ impl core::ops::Deref for Pointer { } } -impl Pointer { +impl Pointer { /// Construct a new `Pointer` event. pub fn new(id: PointerId, location: Location, target: Entity, event: E) -> Self { Self { diff --git a/crates/bevy_ptr/Cargo.toml b/crates/bevy_ptr/Cargo.toml index 0f56880bd41da..d3a1401a8c539 100644 --- a/crates/bevy_ptr/Cargo.toml +++ b/crates/bevy_ptr/Cargo.toml @@ -7,7 +7,7 @@ homepage = "https://bevyengine.org" repository = "https://github.com/bevyengine/bevy" license = "MIT OR Apache-2.0" keywords = ["bevy", "no_std"] -rust-version = "1.85.0" +rust-version = "1.86.0" [dependencies] diff --git a/crates/bevy_reflect/Cargo.toml b/crates/bevy_reflect/Cargo.toml index edca35133e0ce..4ff2f3677cb88 100644 --- a/crates/bevy_reflect/Cargo.toml +++ b/crates/bevy_reflect/Cargo.toml @@ -7,7 +7,7 @@ homepage = "https://bevyengine.org" repository = "https://github.com/bevyengine/bevy" license = "MIT OR Apache-2.0" keywords = ["bevy"] -rust-version = "1.85.0" +rust-version = "1.86.0" [features] default = ["std", "smallvec", "debug"] diff --git a/crates/bevy_reflect/README.md b/crates/bevy_reflect/README.md index 8a145c7a67955..535b11a714725 100644 --- a/crates/bevy_reflect/README.md +++ b/crates/bevy_reflect/README.md @@ -113,7 +113,7 @@ assert!(foo.reflect_partial_eq(&dynamic_struct).unwrap()); ### Trait "reflection" -Call a trait on a given `&dyn Reflect` reference without knowing the underlying type! +Call a trait on a given `&(dyn Reflect + Send + Sync)` reference without knowing the underlying type! ```rust ignore #[derive(Reflect)] @@ -133,8 +133,8 @@ pub trait DoThing { fn do_thing(&self) -> String; } -// First, lets box our type as a Box -let reflect_value: Box = Box::new(MyType { +// First, lets box our type as a Box +let reflect_value: Box = Box::new(MyType { value: "Hello".to_string(), }); @@ -152,15 +152,15 @@ let reflect_do_thing = type_registry .get_type_data::(reflect_value.type_id()) .unwrap(); -// We can use this generated type to convert our `&dyn Reflect` reference to a `&dyn DoThing` reference +// We can use this generated type to convert our `&(dyn Reflect + Send + Sync)` reference to a `&dyn DoThing` reference let my_trait: &dyn DoThing = reflect_do_thing.get(&*reflect_value).unwrap(); // Which means we can now call do_thing(). Magic! println!("{}", my_trait.do_thing()); // This works because the #[reflect(MyTrait)] we put on MyType informed the Reflect derive to insert a new instance -// of ReflectDoThing into MyType's registration. The instance knows how to cast &dyn Reflect to &dyn DoThing, because it -// knows that &dyn Reflect should first be downcasted to &MyType, which can then be safely casted to &dyn DoThing +// of ReflectDoThing into MyType's registration. The instance knows how to cast &(dyn Reflect + Send + Sync) to &dyn DoThing, because it +// knows that &(dyn Reflect + Send + Sync) should first be downcasted to &MyType, which can then be safely casted to &dyn DoThing ``` ## Why make this? diff --git a/crates/bevy_reflect/compile_fail/tests/reflect_derive/generics_fail.stderr b/crates/bevy_reflect/compile_fail/tests/reflect_derive/generics_fail.stderr index 8c4890827de6c..4277515316db4 100644 --- a/crates/bevy_reflect/compile_fail/tests/reflect_derive/generics_fail.stderr +++ b/crates/bevy_reflect/compile_fail/tests/reflect_derive/generics_fail.stderr @@ -20,7 +20,7 @@ error[E0277]: `NoReflect` can not be reflected note: required by a bound in `bevy_reflect::GetField::get_field` --> $BEVY_ROOT/crates/bevy_reflect/src/struct_trait.rs:244:21 | -244 | fn get_field(&self, name: &str) -> Option<&T>; +244 | fn get_field(&self, name: &str) -> Option<&T>; | ^^^^^^^ required by this bound in `GetField::get_field` error[E0277]: `NoReflect` does not provide type registration information diff --git a/crates/bevy_reflect/compile_fail/tests/reflect_remote/nested_fail.rs b/crates/bevy_reflect/compile_fail/tests/reflect_remote/nested_fail.rs index 457f1f75e5f52..776d80ab705d6 100644 --- a/crates/bevy_reflect/compile_fail/tests/reflect_remote/nested_fail.rs +++ b/crates/bevy_reflect/compile_fail/tests/reflect_remote/nested_fail.rs @@ -9,7 +9,7 @@ mod missing_attribute { use bevy_reflect::{FromReflect, GetTypeRegistration, reflect_remote}; #[reflect_remote(super::external_crate::TheirOuter)] - struct MyOuter { + struct MyOuter { // Reason: Missing `#[reflect(remote = ...)]` attribute pub inner: super::external_crate::TheirInner, } @@ -28,7 +28,7 @@ mod incorrect_inner_type { //~| ERROR: `TheirInner` does not implement `TypePath` so cannot provide dynamic type path information //~| ERROR: `TheirInner` does not implement `TypePath` so cannot provide dynamic type path information //~| ERROR: `?` operator has incompatible types - struct MyOuter { + struct MyOuter { // Reason: Should not use `MyInner` directly pub inner: MyInner, //~^ ERROR: mismatched types @@ -44,7 +44,7 @@ mod mismatched_remote_type { #[reflect_remote(super::external_crate::TheirOuter)] //~^ ERROR: mismatched types //~| ERROR: mismatched types - struct MyOuter { + struct MyOuter { // Reason: Should be `MyInner` #[reflect(remote = MyOuter)] //~^ ERROR: mismatched types @@ -62,7 +62,7 @@ mod mismatched_remote_generic { //~^ ERROR: `?` operator has incompatible types //~| ERROR: mismatched types //~| ERROR: mismatched types - struct MyOuter { + struct MyOuter { // Reason: `TheirOuter::inner` is not defined as `TheirInner` #[reflect(remote = MyInner)] pub inner: super::external_crate::TheirInner, diff --git a/crates/bevy_reflect/compile_fail/tests/reflect_remote/nested_pass.rs b/crates/bevy_reflect/compile_fail/tests/reflect_remote/nested_pass.rs index cd79ede57ab5d..1e64af94631c1 100644 --- a/crates/bevy_reflect/compile_fail/tests/reflect_remote/nested_pass.rs +++ b/crates/bevy_reflect/compile_fail/tests/reflect_remote/nested_pass.rs @@ -9,12 +9,12 @@ mod external_crate { } #[reflect_remote(external_crate::TheirOuter)] -struct MyOuter { +struct MyOuter { #[reflect(remote = MyInner)] pub inner: external_crate::TheirInner, } #[reflect_remote(external_crate::TheirInner)] -struct MyInner(pub T); +struct MyInner(pub T); fn main() {} diff --git a/crates/bevy_reflect/derive/src/container_attributes.rs b/crates/bevy_reflect/derive/src/container_attributes.rs index 8b2ae0351f53a..e38dcca22a6e0 100644 --- a/crates/bevy_reflect/derive/src/container_attributes.rs +++ b/crates/bevy_reflect/derive/src/container_attributes.rs @@ -514,8 +514,8 @@ impl ContainerAttributes { ) -> Option { match &self.partial_eq { &TraitImpl::Implemented(span) => Some(quote_spanned! {span=> - fn reflect_partial_eq(&self, value: &dyn #bevy_reflect_path::PartialReflect) -> #FQOption { - let value = ::try_downcast_ref::(value); + fn reflect_partial_eq(&self, value: &(dyn #bevy_reflect_path::PartialReflect + Send + Sync)) -> #FQOption { + let value = ::try_downcast_ref::(value); if let #FQOption::Some(value) = value { #FQOption::Some(::core::cmp::PartialEq::eq(self, value)) } else { @@ -524,7 +524,7 @@ impl ContainerAttributes { } }), &TraitImpl::Custom(ref impl_fn, span) => Some(quote_spanned! {span=> - fn reflect_partial_eq(&self, value: &dyn #bevy_reflect_path::PartialReflect) -> #FQOption { + fn reflect_partial_eq(&self, value: &(dyn #bevy_reflect_path::PartialReflect + Send + Sync)) -> #FQOption { #FQOption::Some(#impl_fn(self, value)) } }), @@ -555,13 +555,13 @@ impl ContainerAttributes { match &self.clone { &TraitImpl::Implemented(span) => Some(quote_spanned! {span=> #[inline] - fn reflect_clone(&self) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::ReflectCloneError> { + fn reflect_clone(&self) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::ReflectCloneError> { #FQResult::Ok(#bevy_reflect_path::__macro_exports::alloc_utils::Box::new(#FQClone::clone(self))) } }), &TraitImpl::Custom(ref impl_fn, span) => Some(quote_spanned! {span=> #[inline] - fn reflect_clone(&self) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::ReflectCloneError> { + fn reflect_clone(&self) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::ReflectCloneError> { #FQResult::Ok(#bevy_reflect_path::__macro_exports::alloc_utils::Box::new(#impl_fn(self))) } }), diff --git a/crates/bevy_reflect/derive/src/derive_data.rs b/crates/bevy_reflect/derive/src/derive_data.rs index f825cb29050e1..08c64a36b530a 100644 --- a/crates/bevy_reflect/derive/src/derive_data.rs +++ b/crates/bevy_reflect/derive/src/derive_data.rs @@ -768,7 +768,7 @@ impl<'a> ReflectStruct<'a> { Some(quote! { #[inline] #[allow(unreachable_code, reason = "Ignored fields without a `clone` attribute will early-return with an error")] - fn reflect_clone(&self) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::ReflectCloneError> { + fn reflect_clone(&self) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::ReflectCloneError> { #FQResult::Ok(#bevy_reflect_path::__macro_exports::alloc_utils::Box::new(#ctor)) } }) @@ -955,7 +955,7 @@ impl<'a> ReflectEnum<'a> { Some(quote! { #[inline] #[allow(unreachable_code, reason = "Ignored fields without a `clone` attribute will early-return with an error")] - fn reflect_clone(&self) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::ReflectCloneError> { + fn reflect_clone(&self) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::ReflectCloneError> { #body } }) diff --git a/crates/bevy_reflect/derive/src/enum_utility.rs b/crates/bevy_reflect/derive/src/enum_utility.rs index 5571b861a6a81..388d84f38b5cb 100644 --- a/crates/bevy_reflect/derive/src/enum_utility.rs +++ b/crates/bevy_reflect/derive/src/enum_utility.rs @@ -39,7 +39,7 @@ pub(crate) trait VariantBuilder: Sized { /// Returns the enum data. fn reflect_enum(&self) -> &ReflectEnum; - /// Returns a token stream that accesses a field of a variant as an `Option`. + /// Returns a token stream that accesses a field of a variant as an `Option`. /// /// The default implementation of this method will return a token stream /// which gets the field dynamically so as to support `dyn Enum`. @@ -65,15 +65,15 @@ pub(crate) trait VariantBuilder: Sized { } } - /// Returns a token stream that unwraps a field of a variant as a `&dyn Reflect` - /// (from an `Option`). + /// Returns a token stream that unwraps a field of a variant as a `&(dyn Reflect + Send + Sync)` + /// (from an `Option`). /// /// # Parameters /// * `field`: The field to access fn unwrap_field(&self, field: VariantField) -> TokenStream; /// Returns a token stream that constructs a field of a variant as a concrete type - /// (from a `&dyn Reflect`). + /// (from a `&(dyn Reflect + Send + Sync)`). /// /// # Parameters /// * `field`: The field to access diff --git a/crates/bevy_reflect/derive/src/from_reflect.rs b/crates/bevy_reflect/derive/src/from_reflect.rs index d994cbd2f79a2..e2b22b4cdc5f1 100644 --- a/crates/bevy_reflect/derive/src/from_reflect.rs +++ b/crates/bevy_reflect/derive/src/from_reflect.rs @@ -29,10 +29,10 @@ pub(crate) fn impl_opaque(meta: &ReflectMeta) -> proc_macro2::TokenStream { let where_from_reflect_clause = WhereClauseOptions::new(meta).extend_where_clause(where_clause); quote! { impl #impl_generics #bevy_reflect_path::FromReflect for #type_path #ty_generics #where_from_reflect_clause { - fn from_reflect(reflect: &dyn #bevy_reflect_path::PartialReflect) -> #FQOption { + fn from_reflect(reflect: &(dyn #bevy_reflect_path::PartialReflect + Send + Sync)) -> #FQOption { #FQOption::Some( #FQClone::clone( - ::try_downcast_ref::<#type_path #ty_generics>(reflect)? + ::try_downcast_ref::<#type_path #ty_generics>(reflect)? ) ) } @@ -74,7 +74,7 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream quote! { impl #impl_generics #bevy_reflect_path::FromReflect for #enum_path #ty_generics #where_from_reflect_clause { - fn from_reflect(#ref_value: &dyn #bevy_reflect_path::PartialReflect) -> #FQOption { + fn from_reflect(#ref_value: &(dyn #bevy_reflect_path::PartialReflect + Send + Sync)) -> #FQOption { if let #bevy_reflect_path::ReflectRef::Enum(#ref_value) = #bevy_reflect_path::PartialReflect::reflect_ref(#ref_value) { @@ -178,7 +178,7 @@ fn impl_struct_internal( quote! { impl #impl_generics #bevy_reflect_path::FromReflect for #struct_path #ty_generics #where_from_reflect_clause { - fn from_reflect(reflect: &dyn #bevy_reflect_path::PartialReflect) -> #FQOption { + fn from_reflect(reflect: &(dyn #bevy_reflect_path::PartialReflect + Send + Sync)) -> #FQOption { if let #bevy_reflect_path::ReflectRef::#ref_struct_type(#ref_struct) = #bevy_reflect_path::PartialReflect::reflect_ref(reflect) { diff --git a/crates/bevy_reflect/derive/src/impls/common.rs b/crates/bevy_reflect/derive/src/impls/common.rs index e8fdadb03e368..5635fa000c988 100644 --- a/crates/bevy_reflect/derive/src/impls/common.rs +++ b/crates/bevy_reflect/derive/src/impls/common.rs @@ -55,26 +55,26 @@ pub fn impl_full_reflect( #any_impls #[inline] - fn into_reflect(self: #bevy_reflect_path::__macro_exports::alloc_utils::Box) -> #bevy_reflect_path::__macro_exports::alloc_utils::Box { + fn into_reflect(self: #bevy_reflect_path::__macro_exports::alloc_utils::Box) -> #bevy_reflect_path::__macro_exports::alloc_utils::Box { self } #[inline] - fn as_reflect(&self) -> &dyn #bevy_reflect_path::Reflect { + fn as_reflect(&self) -> &(dyn #bevy_reflect_path::Reflect + Send + Sync) { self } #[inline] - fn as_reflect_mut(&mut self) -> &mut dyn #bevy_reflect_path::Reflect { + fn as_reflect_mut(&mut self) -> &mut (dyn #bevy_reflect_path::Reflect + Send + Sync) { self } #[inline] fn set( &mut self, - value: #bevy_reflect_path::__macro_exports::alloc_utils::Box - ) -> #FQResult<(), #bevy_reflect_path::__macro_exports::alloc_utils::Box> { - *self = ::take(value)?; + value: #bevy_reflect_path::__macro_exports::alloc_utils::Box + ) -> #FQResult<(), #bevy_reflect_path::__macro_exports::alloc_utils::Box> { + *self = ::take(value)?; #FQResult::Ok(()) } } @@ -96,7 +96,7 @@ pub fn common_partial_reflect_methods( let default_delegate = default_partial_eq_delegate(); default_delegate.map(|func| { quote! { - fn reflect_partial_eq(&self, value: &dyn #bevy_reflect_path::PartialReflect) -> #FQOption { + fn reflect_partial_eq(&self, value: &(dyn #bevy_reflect_path::PartialReflect + Send + Sync)) -> #FQOption { (#func)(self, value) } } @@ -120,32 +120,32 @@ pub fn common_partial_reflect_methods( #[inline] fn try_into_reflect( self: #bevy_reflect_path::__macro_exports::alloc_utils::Box - ) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::__macro_exports::alloc_utils::Box> { + ) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::__macro_exports::alloc_utils::Box> { #FQResult::Ok(self) } #[inline] - fn try_as_reflect(&self) -> #FQOption<&dyn #bevy_reflect_path::Reflect> { + fn try_as_reflect(&self) -> #FQOption<&(dyn #bevy_reflect_path::Reflect + Send + Sync)> { #FQOption::Some(self) } #[inline] - fn try_as_reflect_mut(&mut self) -> #FQOption<&mut dyn #bevy_reflect_path::Reflect> { + fn try_as_reflect_mut(&mut self) -> #FQOption<&mut (dyn #bevy_reflect_path::Reflect + Send + Sync)> { #FQOption::Some(self) } #[inline] - fn into_partial_reflect(self: #bevy_reflect_path::__macro_exports::alloc_utils::Box) -> #bevy_reflect_path::__macro_exports::alloc_utils::Box { + fn into_partial_reflect(self: #bevy_reflect_path::__macro_exports::alloc_utils::Box) -> #bevy_reflect_path::__macro_exports::alloc_utils::Box { self } #[inline] - fn as_partial_reflect(&self) -> &dyn #bevy_reflect_path::PartialReflect { + fn as_partial_reflect(&self) -> &(dyn #bevy_reflect_path::PartialReflect + Send + Sync) { self } #[inline] - fn as_partial_reflect_mut(&mut self) -> &mut dyn #bevy_reflect_path::PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn #bevy_reflect_path::PartialReflect + Send + Sync) { self } diff --git a/crates/bevy_reflect/derive/src/impls/enums.rs b/crates/bevy_reflect/derive/src/impls/enums.rs index 3cbd8cce9510e..f6e7a9e3e9f14 100644 --- a/crates/bevy_reflect/derive/src/impls/enums.rs +++ b/crates/bevy_reflect/derive/src/impls/enums.rs @@ -97,28 +97,28 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream #function_impls impl #impl_generics #bevy_reflect_path::Enum for #enum_path #ty_generics #where_reflect_clause { - fn field(&self, #ref_name: &str) -> #FQOption<&dyn #bevy_reflect_path::PartialReflect> { + fn field(&self, #ref_name: &str) -> #FQOption<&(dyn #bevy_reflect_path::PartialReflect + Send + Sync)> { match #match_this { #(#enum_field,)* _ => #FQOption::None, } } - fn field_at(&self, #ref_index: usize) -> #FQOption<&dyn #bevy_reflect_path::PartialReflect> { + fn field_at(&self, #ref_index: usize) -> #FQOption<&(dyn #bevy_reflect_path::PartialReflect + Send + Sync)> { match #match_this { #(#enum_field_at,)* _ => #FQOption::None, } } - fn field_mut(&mut self, #ref_name: &str) -> #FQOption<&mut dyn #bevy_reflect_path::PartialReflect> { + fn field_mut(&mut self, #ref_name: &str) -> #FQOption<&mut (dyn #bevy_reflect_path::PartialReflect + Send + Sync)> { match #match_this_mut { #(#enum_field_mut,)* _ => #FQOption::None, } } - fn field_at_mut(&mut self, #ref_index: usize) -> #FQOption<&mut dyn #bevy_reflect_path::PartialReflect> { + fn field_at_mut(&mut self, #ref_index: usize) -> #FQOption<&mut (dyn #bevy_reflect_path::PartialReflect + Send + Sync)> { match #match_this_mut { #(#enum_field_at_mut,)* _ => #FQOption::None, @@ -189,7 +189,7 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream #[inline] fn try_apply( &mut self, - #ref_value: &dyn #bevy_reflect_path::PartialReflect + #ref_value: &(dyn #bevy_reflect_path::PartialReflect + Send + Sync) ) -> #FQResult<(), #bevy_reflect_path::ApplyError> { if let #bevy_reflect_path::ReflectRef::Enum(#ref_value) = #bevy_reflect_path::PartialReflect::reflect_ref(#ref_value) { diff --git a/crates/bevy_reflect/derive/src/impls/opaque.rs b/crates/bevy_reflect/derive/src/impls/opaque.rs index 2a08cadc285c4..c8a24de112789 100644 --- a/crates/bevy_reflect/derive/src/impls/opaque.rs +++ b/crates/bevy_reflect/derive/src/impls/opaque.rs @@ -37,14 +37,14 @@ pub(crate) fn impl_opaque(meta: &ReflectMeta) -> proc_macro2::TokenStream { let apply_impl = if let Some(remote_ty) = meta.remote_ty() { let ty = remote_ty.type_path(); quote! { - if let #FQOption::Some(value) = ::try_downcast_ref::<#ty>(value) { + if let #FQOption::Some(value) = ::try_downcast_ref::<#ty>(value) { *self = Self(#FQClone::clone(value)); return #FQResult::Ok(()); } } } else { quote! { - if let #FQOption::Some(value) = ::try_downcast_ref::(value) { + if let #FQOption::Some(value) = ::try_downcast_ref::(value) { *self = #FQClone::clone(value); return #FQResult::Ok(()); } @@ -78,14 +78,14 @@ pub(crate) fn impl_opaque(meta: &ReflectMeta) -> proc_macro2::TokenStream { } #[inline] - fn to_dynamic(&self) -> #bevy_reflect_path::__macro_exports::alloc_utils::Box { + fn to_dynamic(&self) -> #bevy_reflect_path::__macro_exports::alloc_utils::Box { #bevy_reflect_path::__macro_exports::alloc_utils::Box::new(#FQClone::clone(self)) } #[inline] fn try_apply( &mut self, - value: &dyn #bevy_reflect_path::PartialReflect + value: &(dyn #bevy_reflect_path::PartialReflect + Send + Sync) ) -> #FQResult<(), #bevy_reflect_path::ApplyError> { #apply_impl diff --git a/crates/bevy_reflect/derive/src/impls/structs.rs b/crates/bevy_reflect/derive/src/impls/structs.rs index 7e10de3f2bcbc..ec905c76d3df4 100644 --- a/crates/bevy_reflect/derive/src/impls/structs.rs +++ b/crates/bevy_reflect/derive/src/impls/structs.rs @@ -77,28 +77,28 @@ pub(crate) fn impl_struct(reflect_struct: &ReflectStruct) -> proc_macro2::TokenS #function_impls impl #impl_generics #bevy_reflect_path::Struct for #struct_path #ty_generics #where_reflect_clause { - fn field(&self, name: &str) -> #FQOption<&dyn #bevy_reflect_path::PartialReflect> { + fn field(&self, name: &str) -> #FQOption<&(dyn #bevy_reflect_path::PartialReflect + Send + Sync)> { match name { #(#field_names => #fqoption::Some(#fields_ref),)* _ => #FQOption::None, } } - fn field_mut(&mut self, name: &str) -> #FQOption<&mut dyn #bevy_reflect_path::PartialReflect> { + fn field_mut(&mut self, name: &str) -> #FQOption<&mut (dyn #bevy_reflect_path::PartialReflect + Send + Sync)> { match name { #(#field_names => #fqoption::Some(#fields_mut),)* _ => #FQOption::None, } } - fn field_at(&self, index: usize) -> #FQOption<&dyn #bevy_reflect_path::PartialReflect> { + fn field_at(&self, index: usize) -> #FQOption<&(dyn #bevy_reflect_path::PartialReflect + Send + Sync)> { match index { #(#field_indices => #fqoption::Some(#fields_ref),)* _ => #FQOption::None, } } - fn field_at_mut(&mut self, index: usize) -> #FQOption<&mut dyn #bevy_reflect_path::PartialReflect> { + fn field_at_mut(&mut self, index: usize) -> #FQOption<&mut (dyn #bevy_reflect_path::PartialReflect + Send + Sync)> { match index { #(#field_indices => #fqoption::Some(#fields_mut),)* _ => #FQOption::None, @@ -137,7 +137,7 @@ pub(crate) fn impl_struct(reflect_struct: &ReflectStruct) -> proc_macro2::TokenS #[inline] fn try_apply( &mut self, - value: &dyn #bevy_reflect_path::PartialReflect + value: &(dyn #bevy_reflect_path::PartialReflect + Send + Sync) ) -> #FQResult<(), #bevy_reflect_path::ApplyError> { if let #bevy_reflect_path::ReflectRef::Struct(struct_value) = #bevy_reflect_path::PartialReflect::reflect_ref(value) { diff --git a/crates/bevy_reflect/derive/src/impls/tuple_structs.rs b/crates/bevy_reflect/derive/src/impls/tuple_structs.rs index 90c3555230cde..669822e615a66 100644 --- a/crates/bevy_reflect/derive/src/impls/tuple_structs.rs +++ b/crates/bevy_reflect/derive/src/impls/tuple_structs.rs @@ -65,14 +65,14 @@ pub(crate) fn impl_tuple_struct(reflect_struct: &ReflectStruct) -> proc_macro2:: #function_impls impl #impl_generics #bevy_reflect_path::TupleStruct for #struct_path #ty_generics #where_reflect_clause { - fn field(&self, index: usize) -> #FQOption<&dyn #bevy_reflect_path::PartialReflect> { + fn field(&self, index: usize) -> #FQOption<&(dyn #bevy_reflect_path::PartialReflect + Send + Sync)> { match index { #(#field_indices => #fqoption::Some(#fields_ref),)* _ => #FQOption::None, } } - fn field_mut(&mut self, index: usize) -> #FQOption<&mut dyn #bevy_reflect_path::PartialReflect> { + fn field_mut(&mut self, index: usize) -> #FQOption<&mut (dyn #bevy_reflect_path::PartialReflect + Send + Sync)> { match index { #(#field_indices => #fqoption::Some(#fields_mut),)* _ => #FQOption::None, @@ -104,7 +104,7 @@ pub(crate) fn impl_tuple_struct(reflect_struct: &ReflectStruct) -> proc_macro2:: #[inline] fn try_apply( &mut self, - value: &dyn #bevy_reflect_path::PartialReflect + value: &(dyn #bevy_reflect_path::PartialReflect + Send + Sync) ) -> #FQResult<(), #bevy_reflect_path::ApplyError> { if let #bevy_reflect_path::ReflectRef::TupleStruct(struct_value) = #bevy_reflect_path::PartialReflect::reflect_ref(value) { diff --git a/crates/bevy_reflect/derive/src/lib.rs b/crates/bevy_reflect/derive/src/lib.rs index 2d9dfca681568..3ea61fd5cee82 100644 --- a/crates/bevy_reflect/derive/src/lib.rs +++ b/crates/bevy_reflect/derive/src/lib.rs @@ -232,10 +232,10 @@ fn match_reflect_impls(ast: DeriveInput, source: ReflectImplSource) -> TokenStre /// // impl bevy_reflect::Reflect for Foo /// // where /// // Self: Any + Send + Sync, -/// // Vec: FromReflect + TypePath, +/// // Vec: FromReflect + Send + Sync + TypePath, /// ``` /// -/// In this case, `Foo` is given the bounds `Vec: FromReflect + TypePath`, +/// In this case, `Foo` is given the bounds `Vec: FromReflect + Send + Sync + TypePath`, /// which requires that `Foo` implements `FromReflect`, /// which requires that `Vec` implements `FromReflect`, /// and so on, resulting in the error. @@ -286,7 +286,7 @@ fn match_reflect_impls(ast: DeriveInput, source: ReflectImplSource) -> TokenStre /// // Self: Any + Send + Sync, /// // T::Assoc: Default, /// // T: TypePath, -/// // T::Assoc: FromReflect + TypePath, +/// // T::Assoc: FromReflect + Send + Sync + TypePath, /// // T::Assoc: List, /// // {/* ... */} /// ``` @@ -529,7 +529,7 @@ pub fn derive_type_path(input: TokenStream) -> TokenStream { /// .unwrap(); /// /// // Then use it on reflected data -/// let reflected: Box = Box::new(SomeStruct); +/// let reflected: Box = Box::new(SomeStruct); /// let reflected_my_trait: &dyn MyTrait = my_trait.get(&*reflected).unwrap(); /// assert_eq!("Hello, World!", reflected_my_trait.print()); /// ``` diff --git a/crates/bevy_reflect/derive/src/serialization.rs b/crates/bevy_reflect/derive/src/serialization.rs index 75df7b7b930b2..68a7e89fcea07 100644 --- a/crates/bevy_reflect/derive/src/serialization.rs +++ b/crates/bevy_reflect/derive/src/serialization.rs @@ -73,7 +73,7 @@ impl SerializationDataDef { pub(crate) struct SkippedFieldDef { /// The default function for this field. /// - /// This is of type `fn() -> Box`. + /// This is of type `fn() -> Box`. default_fn: proc_macro2::TokenStream, } diff --git a/crates/bevy_reflect/derive/src/trait_reflection.rs b/crates/bevy_reflect/derive/src/trait_reflection.rs index 8df40e47a5fd0..4387627ee40d2 100644 --- a/crates/bevy_reflect/derive/src/trait_reflection.rs +++ b/crates/bevy_reflect/derive/src/trait_reflection.rs @@ -37,13 +37,13 @@ pub(crate) fn reflect_trait(_args: &TokenStream, input: TokenStream) -> TokenStr " A type generated by the #[reflect_trait] macro for the `{trait_ident}` trait.\n\n This allows casting from `dyn Reflect` to `dyn {trait_ident}`.", ); let get_doc = format!( - " Downcast a `&dyn Reflect` type to `&dyn {trait_ident}`.\n\n If the type cannot be downcast, `None` is returned.", + " Downcast a `&(dyn Reflect + Send + Sync)` type to `&dyn {trait_ident}`.\n\n If the type cannot be downcast, `None` is returned.", ); let get_mut_doc = format!( - " Downcast a `&mut dyn Reflect` type to `&mut dyn {trait_ident}`.\n\n If the type cannot be downcast, `None` is returned.", + " Downcast a `&mut (dyn Reflect + Send + Sync)` type to `&mut dyn {trait_ident}`.\n\n If the type cannot be downcast, `None` is returned.", ); let get_box_doc = format!( - " Downcast a `Box` type to `Box`.\n\n If the type cannot be downcast, this will return `Err(Box)`.", + " Downcast a `Box` type to `Box`.\n\n If the type cannot be downcast, this will return `Err(Box)`.", ); TokenStream::from(quote! { @@ -52,39 +52,39 @@ pub(crate) fn reflect_trait(_args: &TokenStream, input: TokenStream) -> TokenStr #[doc = #struct_doc] #[derive(#FQClone)] #trait_vis struct #reflect_trait_ident { - get_func: fn(&dyn #bevy_reflect_path::Reflect) -> #FQOption<&dyn #trait_ident>, - get_mut_func: fn(&mut dyn #bevy_reflect_path::Reflect) -> #FQOption<&mut dyn #trait_ident>, - get_boxed_func: fn(#bevy_reflect_path::__macro_exports::alloc_utils::Box) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::__macro_exports::alloc_utils::Box>, + get_func: fn(&(dyn #bevy_reflect_path::Reflect + Send + Sync)) -> #FQOption<&dyn #trait_ident>, + get_mut_func: fn(&mut (dyn #bevy_reflect_path::Reflect + Send + Sync)) -> #FQOption<&mut dyn #trait_ident>, + get_boxed_func: fn(#bevy_reflect_path::__macro_exports::alloc_utils::Box) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::__macro_exports::alloc_utils::Box>, } impl #reflect_trait_ident { #[doc = #get_doc] - pub fn get<'a>(&self, reflect_value: &'a dyn #bevy_reflect_path::Reflect) -> #FQOption<&'a dyn #trait_ident> { + pub fn get<'a>(&self, reflect_value: &'a (dyn #bevy_reflect_path::Reflect + Send + Sync)) -> #FQOption<&'a dyn #trait_ident> { (self.get_func)(reflect_value) } #[doc = #get_mut_doc] - pub fn get_mut<'a>(&self, reflect_value: &'a mut dyn #bevy_reflect_path::Reflect) -> #FQOption<&'a mut dyn #trait_ident> { + pub fn get_mut<'a>(&self, reflect_value: &'a mut (dyn #bevy_reflect_path::Reflect + Send + Sync)) -> #FQOption<&'a mut dyn #trait_ident> { (self.get_mut_func)(reflect_value) } #[doc = #get_box_doc] - pub fn get_boxed(&self, reflect_value: #bevy_reflect_path::__macro_exports::alloc_utils::Box) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::__macro_exports::alloc_utils::Box> { + pub fn get_boxed(&self, reflect_value: #bevy_reflect_path::__macro_exports::alloc_utils::Box) -> #FQResult<#bevy_reflect_path::__macro_exports::alloc_utils::Box, #bevy_reflect_path::__macro_exports::alloc_utils::Box> { (self.get_boxed_func)(reflect_value) } } - impl #bevy_reflect_path::FromType for #reflect_trait_ident { + impl #bevy_reflect_path::FromType for #reflect_trait_ident { fn from_type() -> Self { Self { get_func: |reflect_value| { - ::downcast_ref::(reflect_value).map(|value| value as &dyn #trait_ident) + ::downcast_ref::(reflect_value).map(|value| value as &dyn #trait_ident) }, get_mut_func: |reflect_value| { - ::downcast_mut::(reflect_value).map(|value| value as &mut dyn #trait_ident) + ::downcast_mut::(reflect_value).map(|value| value as &mut dyn #trait_ident) }, get_boxed_func: |reflect_value| { - ::downcast::(reflect_value).map(|value| value as #bevy_reflect_path::__macro_exports::alloc_utils::Box) + ::downcast::(reflect_value).map(|value| value as #bevy_reflect_path::__macro_exports::alloc_utils::Box) } } } diff --git a/crates/bevy_reflect/derive/src/where_clause_options.rs b/crates/bevy_reflect/derive/src/where_clause_options.rs index 1551e008d017c..4921be302f459 100644 --- a/crates/bevy_reflect/derive/src/where_clause_options.rs +++ b/crates/bevy_reflect/derive/src/where_clause_options.rs @@ -56,7 +56,7 @@ impl<'a, 'b> WhereClauseOptions<'a, 'b> { /// T: TypePath, /// U: TypePath, /// // Field bounds - /// T: FromReflect + TypePath, + /// T: FromReflect + Send + Sync + TypePath, /// ``` /// /// If we had added `#[reflect(where T: MyTrait)]` to the type, it would instead generate: @@ -69,7 +69,7 @@ impl<'a, 'b> WhereClauseOptions<'a, 'b> { /// T: TypePath, /// U: TypePath, /// // Field bounds - /// T: FromReflect + TypePath, + /// T: FromReflect + Send + Sync + TypePath, /// // Custom bounds /// T: MyTrait, /// ``` @@ -175,9 +175,9 @@ impl<'a, 'b> WhereClauseOptions<'a, 'b> { let bevy_reflect_path = self.meta.bevy_reflect_path(); if self.meta.from_reflect().should_auto_derive() { - quote!(#bevy_reflect_path::FromReflect) + quote!(#bevy_reflect_path::FromReflect + Send + Sync) } else { - quote!(#bevy_reflect_path::PartialReflect) + quote!(#bevy_reflect_path::PartialReflect + Send + Sync) } } diff --git a/crates/bevy_reflect/src/array.rs b/crates/bevy_reflect/src/array.rs index 9ad906cfce1c5..e8cba87553ac2 100644 --- a/crates/bevy_reflect/src/array.rs +++ b/crates/bevy_reflect/src/array.rs @@ -36,7 +36,7 @@ use core::{ /// let foo: &dyn Array = &[123_u32, 456_u32, 789_u32]; /// assert_eq!(foo.len(), 3); /// -/// let field: &dyn PartialReflect = foo.get(0).unwrap(); +/// let field: &(dyn PartialReflect + Send + Sync) = foo.get(0).unwrap(); /// assert_eq!(field.try_downcast_ref::(), Some(&123)); /// ``` /// @@ -49,10 +49,10 @@ use core::{ /// [`Deserialize`]: ::serde::Deserialize pub trait Array: PartialReflect { /// Returns a reference to the element at `index`, or `None` if out of bounds. - fn get(&self, index: usize) -> Option<&dyn PartialReflect>; + fn get(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)>; /// Returns a mutable reference to the element at `index`, or `None` if out of bounds. - fn get_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>; + fn get_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)>; /// Returns the number of elements in the array. fn len(&self) -> usize; @@ -66,7 +66,7 @@ pub trait Array: PartialReflect { fn iter(&self) -> ArrayIter; /// Drain the elements of this array to get a vector of owned values. - fn drain(self: Box) -> Vec>; + fn drain(self: Box) -> Vec>; /// Clones the list, producing a [`DynamicArray`]. #[deprecated(since = "0.16.0", note = "use `to_dynamic_array` instead")] @@ -106,7 +106,7 @@ impl ArrayInfo { /// # Arguments /// /// * `capacity`: The maximum capacity of the underlying array. - pub fn new( + pub fn new( capacity: usize, ) -> Self { Self { @@ -169,12 +169,12 @@ impl ArrayInfo { #[derive(Debug)] pub struct DynamicArray { pub(crate) represented_type: Option<&'static TypeInfo>, - pub(crate) values: Box<[Box]>, + pub(crate) values: Box<[Box]>, } impl DynamicArray { #[inline] - pub fn new(values: Box<[Box]>) -> Self { + pub fn new(values: Box<[Box]>) -> Self { Self { represented_type: None, values, @@ -208,37 +208,39 @@ impl PartialReflect for DynamicArray { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } #[inline] - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } #[inline] - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Err(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { None } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { None } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { array_apply(self, value); } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { array_try_apply(self, value) } @@ -267,7 +269,7 @@ impl PartialReflect for DynamicArray { array_hash(self) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { array_partial_eq(self, value) } @@ -285,12 +287,12 @@ impl PartialReflect for DynamicArray { impl Array for DynamicArray { #[inline] - fn get(&self, index: usize) -> Option<&dyn PartialReflect> { + fn get(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)> { self.values.get(index).map(|value| &**value) } #[inline] - fn get_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect> { + fn get_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)> { self.values.get_mut(index).map(|value| &mut **value) } @@ -305,13 +307,13 @@ impl Array for DynamicArray { } #[inline] - fn drain(self: Box) -> Vec> { + fn drain(self: Box) -> Vec> { self.values.into_vec() } } -impl FromIterator> for DynamicArray { - fn from_iter>>(values: I) -> Self { +impl FromIterator> for DynamicArray { + fn from_iter>>(values: I) -> Self { Self { represented_type: None, values: values.into_iter().collect::>().into_boxed_slice(), @@ -319,7 +321,7 @@ impl FromIterator> for DynamicArray { } } -impl FromIterator for DynamicArray { +impl FromIterator for DynamicArray { fn from_iter>(values: I) -> Self { values .into_iter() @@ -329,7 +331,7 @@ impl FromIterator for DynamicArray { } impl IntoIterator for DynamicArray { - type Item = Box; + type Item = Box; type IntoIter = alloc::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { @@ -338,7 +340,7 @@ impl IntoIterator for DynamicArray { } impl<'a> IntoIterator for &'a DynamicArray { - type Item = &'a dyn PartialReflect; + type Item = &'a (dyn PartialReflect + Send + Sync); type IntoIter = ArrayIter<'a>; fn into_iter(self) -> Self::IntoIter { @@ -363,7 +365,7 @@ impl ArrayIter<'_> { } impl<'a> Iterator for ArrayIter<'a> { - type Item = &'a dyn PartialReflect; + type Item = &'a (dyn PartialReflect + Send + Sync); #[inline] fn next(&mut self) -> Option { @@ -400,7 +402,7 @@ pub fn array_hash(array: &A) -> Option { /// * Panics if the two arrays have differing lengths. /// * Panics if the reflected value is not a [valid array](ReflectRef::Array). #[inline] -pub fn array_apply(array: &mut A, reflect: &dyn PartialReflect) { +pub fn array_apply(array: &mut A, reflect: &(dyn PartialReflect + Send + Sync)) { if let ReflectRef::Array(reflect_array) = reflect.reflect_ref() { if array.len() != reflect_array.len() { panic!("Attempted to apply different sized `Array` types."); @@ -426,7 +428,7 @@ pub fn array_apply(array: &mut A, reflect: &dyn PartialReflec #[inline] pub fn array_try_apply( array: &mut A, - reflect: &dyn PartialReflect, + reflect: &(dyn PartialReflect + Send + Sync), ) -> Result<(), ApplyError> { let reflect_array = reflect.reflect_ref().as_array()?; @@ -452,7 +454,7 @@ pub fn array_try_apply( #[inline] pub fn array_partial_eq( array: &A, - reflect: &dyn PartialReflect, + reflect: &(dyn PartialReflect + Send + Sync), ) -> Option { match reflect.reflect_ref() { ReflectRef::Array(reflect_array) if reflect_array.len() == array.len() => { @@ -475,7 +477,7 @@ pub fn array_partial_eq( /// ``` /// use bevy_reflect::Reflect; /// -/// let my_array: &dyn Reflect = &[1, 2, 3]; +/// let my_array: &(dyn Reflect + Send + Sync) = &[1, 2, 3]; /// println!("{:#?}", my_array); /// /// // Output: diff --git a/crates/bevy_reflect/src/attributes.rs b/crates/bevy_reflect/src/attributes.rs index a6edefab25c65..d110e42c11929 100644 --- a/crates/bevy_reflect/src/attributes.rs +++ b/crates/bevy_reflect/src/attributes.rs @@ -42,7 +42,7 @@ impl CustomAttributes { /// Inserts a custom attribute into the collection. /// /// Note that this will overwrite any existing attribute of the same type. - pub fn with_attribute(mut self, value: T) -> Self { + pub fn with_attribute(mut self, value: T) -> Self { self.attributes .insert(TypeId::of::(), CustomAttribute::new(value)); @@ -50,7 +50,7 @@ impl CustomAttributes { } /// Returns `true` if this collection contains a custom attribute of the specified type. - pub fn contains(&self) -> bool { + pub fn contains(&self) -> bool { self.attributes.contains_key(&TypeId::of::()) } @@ -60,17 +60,17 @@ impl CustomAttributes { } /// Gets a custom attribute by type. - pub fn get(&self) -> Option<&T> { + pub fn get(&self) -> Option<&T> { self.attributes.get(&TypeId::of::())?.value::() } /// Gets a custom attribute by its [`TypeId`]. - pub fn get_by_id(&self, id: TypeId) -> Option<&dyn Reflect> { + pub fn get_by_id(&self, id: TypeId) -> Option<&(dyn Reflect + Send + Sync)> { Some(self.attributes.get(&id)?.reflect_value()) } /// Returns an iterator over all custom attributes. - pub fn iter(&self) -> impl ExactSizeIterator { + pub fn iter(&self) -> impl ExactSizeIterator { self.attributes .iter() .map(|(key, value)| (key, value.reflect_value())) @@ -94,21 +94,21 @@ impl Debug for CustomAttributes { } struct CustomAttribute { - value: Box, + value: Box, } impl CustomAttribute { - pub fn new(value: T) -> Self { + pub fn new(value: T) -> Self { Self { value: Box::new(value), } } - pub fn value(&self) -> Option<&T> { + pub fn value(&self) -> Option<&T> { self.value.downcast_ref() } - pub fn reflect_value(&self) -> &dyn Reflect { + pub fn reflect_value(&self) -> &(dyn Reflect + Send + Sync) { &*self.value } } @@ -124,9 +124,9 @@ impl Debug for CustomAttribute { /// Implements the following methods: /// /// * `fn custom_attributes(&self) -> &CustomAttributes` -/// * `fn get_attribute(&self) -> Option<&T>` -/// * `fn get_attribute_by_id(&self, id: TypeId) -> Option<&dyn Reflect>` -/// * `fn has_attribute(&self) -> bool` +/// * `fn get_attribute(&self) -> Option<&T>` +/// * `fn get_attribute_by_id(&self, id: TypeId) -> Option<&(dyn Reflect + Send + Sync)>` +/// * `fn has_attribute(&self) -> bool` /// * `fn has_attribute_by_id(&self, id: TypeId) -> bool` /// /// # Params @@ -148,20 +148,20 @@ macro_rules! impl_custom_attribute_methods { /// Gets a custom attribute by type. /// /// For dynamically accessing an attribute, see [`get_attribute_by_id`](Self::get_attribute_by_id). - pub fn get_attribute(&$self) -> Option<&T> { + pub fn get_attribute(&$self) -> Option<&T> { $self.custom_attributes().get::() } /// Gets a custom attribute by its [`TypeId`](core::any::TypeId). /// /// This is the dynamic equivalent of [`get_attribute`](Self::get_attribute). - pub fn get_attribute_by_id(&$self, id: ::core::any::TypeId) -> Option<&dyn $crate::Reflect> { + pub fn get_attribute_by_id(&$self, id: ::core::any::TypeId) -> Option<&(dyn $crate::Reflect + Send + Sync)> { $self.custom_attributes().get_by_id(id) } #[doc = concat!("Returns `true` if this ", $term, " has a custom attribute of the specified type.")] #[doc = "\n\nFor dynamically checking if an attribute exists, see [`has_attribute_by_id`](Self::has_attribute_by_id)."] - pub fn has_attribute(&$self) -> bool { + pub fn has_attribute(&$self) -> bool { $self.custom_attributes().contains::() } diff --git a/crates/bevy_reflect/src/enums/dynamic_enum.rs b/crates/bevy_reflect/src/enums/dynamic_enum.rs index 3380921fbe152..ef671ad02ef89 100644 --- a/crates/bevy_reflect/src/enums/dynamic_enum.rs +++ b/crates/bevy_reflect/src/enums/dynamic_enum.rs @@ -205,7 +205,7 @@ impl DynamicEnum { } impl Enum for DynamicEnum { - fn field(&self, name: &str) -> Option<&dyn PartialReflect> { + fn field(&self, name: &str) -> Option<&(dyn PartialReflect + Send + Sync)> { if let DynamicVariant::Struct(data) = &self.variant { data.field(name) } else { @@ -213,7 +213,7 @@ impl Enum for DynamicEnum { } } - fn field_at(&self, index: usize) -> Option<&dyn PartialReflect> { + fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)> { if let DynamicVariant::Tuple(data) = &self.variant { data.field(index) } else { @@ -221,7 +221,7 @@ impl Enum for DynamicEnum { } } - fn field_mut(&mut self, name: &str) -> Option<&mut dyn PartialReflect> { + fn field_mut(&mut self, name: &str) -> Option<&mut (dyn PartialReflect + Send + Sync)> { if let DynamicVariant::Struct(data) = &mut self.variant { data.field_mut(name) } else { @@ -229,7 +229,7 @@ impl Enum for DynamicEnum { } } - fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect> { + fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)> { if let DynamicVariant::Tuple(data) = &mut self.variant { data.field_mut(index) } else { @@ -298,34 +298,36 @@ impl PartialReflect for DynamicEnum { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } #[inline] - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } #[inline] - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Err(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { None } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { None } #[inline] - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { let value = value.reflect_ref().as_enum()?; if Enum::variant_name(self) == value.variant_name() { @@ -399,7 +401,7 @@ impl PartialReflect for DynamicEnum { } #[inline] - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { enum_partial_eq(self, value) } diff --git a/crates/bevy_reflect/src/enums/enum_trait.rs b/crates/bevy_reflect/src/enums/enum_trait.rs index 4df7aea5270a7..ca6ba222e447d 100644 --- a/crates/bevy_reflect/src/enums/enum_trait.rs +++ b/crates/bevy_reflect/src/enums/enum_trait.rs @@ -97,15 +97,15 @@ pub trait Enum: PartialReflect { /// Returns a reference to the value of the field (in the current variant) with the given name. /// /// For non-[`VariantType::Struct`] variants, this should return `None`. - fn field(&self, name: &str) -> Option<&dyn PartialReflect>; + fn field(&self, name: &str) -> Option<&(dyn PartialReflect + Send + Sync)>; /// Returns a reference to the value of the field (in the current variant) at the given index. - fn field_at(&self, index: usize) -> Option<&dyn PartialReflect>; + fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)>; /// Returns a mutable reference to the value of the field (in the current variant) with the given name. /// /// For non-[`VariantType::Struct`] variants, this should return `None`. - fn field_mut(&mut self, name: &str) -> Option<&mut dyn PartialReflect>; + fn field_mut(&mut self, name: &str) -> Option<&mut (dyn PartialReflect + Send + Sync)>; /// Returns a mutable reference to the value of the field (in the current variant) at the given index. - fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>; + fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)>; /// Returns the index of the field (in the current variant) with the given name. /// /// For non-[`VariantType::Struct`] variants, this should return `None`. @@ -301,8 +301,8 @@ impl<'a> Iterator for VariantFieldIter<'a> { impl<'a> ExactSizeIterator for VariantFieldIter<'a> {} pub enum VariantField<'a> { - Struct(&'a str, &'a dyn PartialReflect), - Tuple(&'a dyn PartialReflect), + Struct(&'a str, &'a (dyn PartialReflect + Send + Sync)), + Tuple(&'a (dyn PartialReflect + Send + Sync)), } impl<'a> VariantField<'a> { @@ -314,7 +314,7 @@ impl<'a> VariantField<'a> { } } - pub fn value(&self) -> &'a dyn PartialReflect { + pub fn value(&self) -> &'a (dyn PartialReflect + Send + Sync) { match *self { Self::Struct(_, value) | Self::Tuple(value) => value, } diff --git a/crates/bevy_reflect/src/enums/helpers.rs b/crates/bevy_reflect/src/enums/helpers.rs index 659d0bd7bc823..356236e0e52d4 100644 --- a/crates/bevy_reflect/src/enums/helpers.rs +++ b/crates/bevy_reflect/src/enums/helpers.rs @@ -26,7 +26,10 @@ pub fn enum_hash(value: &TEnum) -> Option { /// [`PartialReflect::reflect_partial_eq`] returns `Some(true)` for the two field /// values. #[inline] -pub fn enum_partial_eq(a: &TEnum, b: &dyn PartialReflect) -> Option { +pub fn enum_partial_eq( + a: &TEnum, + b: &(dyn PartialReflect + Send + Sync), +) -> Option { // Both enums? let ReflectRef::Enum(b) = b.reflect_ref() else { return Some(false); @@ -90,7 +93,7 @@ pub fn enum_partial_eq(a: &TEnum, b: &dyn PartialReflect) /// C {value: i32} /// } /// -/// let my_enum: &dyn Reflect = &MyEnum::B(123); +/// let my_enum: &(dyn Reflect + Send + Sync) = &MyEnum::B(123); /// println!("{:#?}", my_enum); /// /// // Output: diff --git a/crates/bevy_reflect/src/enums/mod.rs b/crates/bevy_reflect/src/enums/mod.rs index fd657ffa7f25a..042c19ab35233 100644 --- a/crates/bevy_reflect/src/enums/mod.rs +++ b/crates/bevy_reflect/src/enums/mod.rs @@ -494,7 +494,7 @@ mod tests { #[test] fn enum_should_apply() { - let mut value: Box = Box::new(MyEnum::A); + let mut value: Box = Box::new(MyEnum::A); // === MyEnum::A -> MyEnum::A === // value.apply(&MyEnum::A); @@ -549,7 +549,7 @@ mod tests { #[test] fn enum_should_set() { - let mut value: Box = Box::new(MyEnum::A); + let mut value: Box = Box::new(MyEnum::A); // === MyEnum::A -> MyEnum::A === // value.set(Box::new(MyEnum::A)).unwrap(); @@ -620,71 +620,71 @@ mod tests { C2 { value: f32 }, } - let a: &dyn PartialReflect = &TestEnum::A; - let b: &dyn PartialReflect = &TestEnum::A; + let a: &(dyn PartialReflect + Send + Sync) = &TestEnum::A; + let b: &(dyn PartialReflect + Send + Sync) = &TestEnum::A; assert!( a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::A == TestEnum::A" ); - let a: &dyn PartialReflect = &TestEnum::A; - let b: &dyn PartialReflect = &TestEnum::A1; + let a: &(dyn PartialReflect + Send + Sync) = &TestEnum::A; + let b: &(dyn PartialReflect + Send + Sync) = &TestEnum::A1; assert!( !a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::A != TestEnum::A1" ); - let a: &dyn PartialReflect = &TestEnum::B(123); - let b: &dyn PartialReflect = &TestEnum::B(123); + let a: &(dyn PartialReflect + Send + Sync) = &TestEnum::B(123); + let b: &(dyn PartialReflect + Send + Sync) = &TestEnum::B(123); assert!( a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::B(123) == TestEnum::B(123)" ); - let a: &dyn PartialReflect = &TestEnum::B(123); - let b: &dyn PartialReflect = &TestEnum::B(321); + let a: &(dyn PartialReflect + Send + Sync) = &TestEnum::B(123); + let b: &(dyn PartialReflect + Send + Sync) = &TestEnum::B(321); assert!( !a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::B(123) != TestEnum::B(321)" ); - let a: &dyn PartialReflect = &TestEnum::B(123); - let b: &dyn PartialReflect = &TestEnum::B1(123); + let a: &(dyn PartialReflect + Send + Sync) = &TestEnum::B(123); + let b: &(dyn PartialReflect + Send + Sync) = &TestEnum::B1(123); assert!( !a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::B(123) != TestEnum::B1(123)" ); - let a: &dyn PartialReflect = &TestEnum::B(123); - let b: &dyn PartialReflect = &TestEnum::B2(123, 123); + let a: &(dyn PartialReflect + Send + Sync) = &TestEnum::B(123); + let b: &(dyn PartialReflect + Send + Sync) = &TestEnum::B2(123, 123); assert!( !a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::B(123) != TestEnum::B2(123, 123)" ); - let a: &dyn PartialReflect = &TestEnum::C { value: 123 }; - let b: &dyn PartialReflect = &TestEnum::C { value: 123 }; + let a: &(dyn PartialReflect + Send + Sync) = &TestEnum::C { value: 123 }; + let b: &(dyn PartialReflect + Send + Sync) = &TestEnum::C { value: 123 }; assert!( a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::C{{value: 123}} == TestEnum::C{{value: 123}}" ); - let a: &dyn PartialReflect = &TestEnum::C { value: 123 }; - let b: &dyn PartialReflect = &TestEnum::C { value: 321 }; + let a: &(dyn PartialReflect + Send + Sync) = &TestEnum::C { value: 123 }; + let b: &(dyn PartialReflect + Send + Sync) = &TestEnum::C { value: 321 }; assert!( !a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::C{{value: 123}} != TestEnum::C{{value: 321}}" ); - let a: &dyn PartialReflect = &TestEnum::C { value: 123 }; - let b: &dyn PartialReflect = &TestEnum::C1 { value: 123 }; + let a: &(dyn PartialReflect + Send + Sync) = &TestEnum::C { value: 123 }; + let b: &(dyn PartialReflect + Send + Sync) = &TestEnum::C1 { value: 123 }; assert!( !a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::C{{value: 123}} != TestEnum::C1{{value: 123}}" ); - let a: &dyn PartialReflect = &TestEnum::C { value: 123 }; - let b: &dyn PartialReflect = &TestEnum::C2 { value: 1.23 }; + let a: &(dyn PartialReflect + Send + Sync) = &TestEnum::C { value: 123 }; + let b: &(dyn PartialReflect + Send + Sync) = &TestEnum::C2 { value: 1.23 }; assert!( !a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::C{{value: 123}} != TestEnum::C2{{value: 1.23}}" diff --git a/crates/bevy_reflect/src/fields.rs b/crates/bevy_reflect/src/fields.rs index 393bfcb2e2ea6..e1850a59048b7 100644 --- a/crates/bevy_reflect/src/fields.rs +++ b/crates/bevy_reflect/src/fields.rs @@ -20,7 +20,9 @@ pub struct NamedField { impl NamedField { /// Create a new [`NamedField`]. - pub fn new(name: &'static str) -> Self { + pub fn new( + name: &'static str, + ) -> Self { Self { name, type_info: T::maybe_type_info, @@ -82,7 +84,7 @@ pub struct UnnamedField { } impl UnnamedField { - pub fn new(index: usize) -> Self { + pub fn new(index: usize) -> Self { Self { index, type_info: T::maybe_type_info, diff --git a/crates/bevy_reflect/src/from_reflect.rs b/crates/bevy_reflect/src/from_reflect.rs index dc113d869f3c7..9b8d7ba7f8d2d 100644 --- a/crates/bevy_reflect/src/from_reflect.rs +++ b/crates/bevy_reflect/src/from_reflect.rs @@ -28,7 +28,7 @@ use alloc::boxed::Box; )] pub trait FromReflect: Reflect + Sized { /// Constructs a concrete instance of `Self` from a reflected value. - fn from_reflect(reflect: &dyn PartialReflect) -> Option; + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option; /// Attempts to downcast the given value to `Self` using, /// constructing the value using [`from_reflect`] if that fails. @@ -41,8 +41,8 @@ pub trait FromReflect: Reflect + Sized { /// [`DynamicStruct`]: crate::DynamicStruct /// [`DynamicList`]: crate::DynamicList fn take_from_reflect( - reflect: Box, - ) -> Result> { + reflect: Box, + ) -> Result> { match reflect.try_take::() { Ok(value) => Ok(value), Err(value) => match Self::from_reflect(value.as_ref()) { @@ -95,7 +95,7 @@ pub trait FromReflect: Reflect + Sized { /// let registration = registry.get_with_type_path(::type_path()).unwrap(); /// let rfr = registration.data::().unwrap(); /// -/// let concrete: Box = rfr.from_reflect(&reflected).unwrap(); +/// let concrete: Box = rfr.from_reflect(&reflected).unwrap(); /// /// assert_eq!(Foo(123), concrete.take::().unwrap()); /// ``` @@ -104,24 +104,28 @@ pub trait FromReflect: Reflect + Sized { /// [`DynamicEnum`]: crate::DynamicEnum #[derive(Clone)] pub struct ReflectFromReflect { - from_reflect: fn(&dyn PartialReflect) -> Option>, + from_reflect: fn(&(dyn PartialReflect + Send + Sync)) -> Option>, } impl ReflectFromReflect { /// Perform a [`FromReflect::from_reflect`] conversion on the given reflection object. /// /// This will convert the object to a concrete type if it wasn't already, and return - /// the value as `Box`. - pub fn from_reflect(&self, reflect_value: &dyn PartialReflect) -> Option> { + /// the value as `Box`. + pub fn from_reflect( + &self, + reflect_value: &(dyn PartialReflect + Send + Sync), + ) -> Option> { (self.from_reflect)(reflect_value) } } -impl FromType for ReflectFromReflect { +impl FromType for ReflectFromReflect { fn from_type() -> Self { Self { from_reflect: |reflect_value| { - T::from_reflect(reflect_value).map(|value| Box::new(value) as Box) + T::from_reflect(reflect_value) + .map(|value| Box::new(value) as Box) }, } } diff --git a/crates/bevy_reflect/src/func/args/arg.rs b/crates/bevy_reflect/src/func/args/arg.rs index 8ca03aafd36ff..536e456ca04f8 100644 --- a/crates/bevy_reflect/src/func/args/arg.rs +++ b/crates/bevy_reflect/src/func/args/arg.rs @@ -82,7 +82,7 @@ impl<'a> Arg<'a> { /// let value = args.take_owned::().unwrap(); /// assert_eq!(value, 123); /// ``` - pub fn take_owned(self) -> Result { + pub fn take_owned(self) -> Result { match self.value { ArgValue::Owned(arg) => arg.try_take().map_err(|arg| ArgError::UnexpectedType { index: self.index, @@ -117,7 +117,7 @@ impl<'a> Arg<'a> { /// let value = args.take_ref::().unwrap(); /// assert_eq!(*value, 123); /// ``` - pub fn take_ref(self) -> Result<&'a T, ArgError> { + pub fn take_ref(self) -> Result<&'a T, ArgError> { match self.value { ArgValue::Owned(_) => Err(ArgError::InvalidOwnership { index: self.index, @@ -156,7 +156,7 @@ impl<'a> Arg<'a> { /// let value = args.take_mut::().unwrap(); /// assert_eq!(*value, 123); /// ``` - pub fn take_mut(self) -> Result<&'a mut T, ArgError> { + pub fn take_mut(self) -> Result<&'a mut T, ArgError> { match self.value { ArgValue::Owned(_) => Err(ArgError::InvalidOwnership { index: self.index, @@ -185,7 +185,7 @@ impl<'a> Arg<'a> { pub fn is(&self) -> bool { self.value .try_as_reflect() - .map(::is::) + .map(::is::) .unwrap_or_default() } } @@ -196,13 +196,13 @@ impl<'a> Arg<'a> { /// [`DynamicFunctionMut`]: crate::func::DynamicFunctionMut #[derive(Debug)] pub enum ArgValue<'a> { - Owned(Box), - Ref(&'a dyn PartialReflect), - Mut(&'a mut dyn PartialReflect), + Owned(Box), + Ref(&'a (dyn PartialReflect + Send + Sync)), + Mut(&'a mut (dyn PartialReflect + Send + Sync)), } impl<'a> Deref for ArgValue<'a> { - type Target = dyn PartialReflect; + type Target = dyn PartialReflect + Send + Sync; fn deref(&self) -> &Self::Target { match self { diff --git a/crates/bevy_reflect/src/func/args/list.rs b/crates/bevy_reflect/src/func/args/list.rs index ee0964e71a644..f9a0c837a90c5 100644 --- a/crates/bevy_reflect/src/func/args/list.rs +++ b/crates/bevy_reflect/src/func/args/list.rs @@ -74,7 +74,7 @@ impl<'a> ArgList<'a> { /// /// If an argument was previously removed from the beginning of the list, /// this method will also re-index the list. - pub fn push_ref(&mut self, arg: &'a dyn PartialReflect) { + pub fn push_ref(&mut self, arg: &'a (dyn PartialReflect + Send + Sync)) { self.push_arg(ArgValue::Ref(arg)); } @@ -82,7 +82,7 @@ impl<'a> ArgList<'a> { /// /// If an argument was previously removed from the beginning of the list, /// this method will also re-index the list. - pub fn push_mut(&mut self, arg: &'a mut dyn PartialReflect) { + pub fn push_mut(&mut self, arg: &'a mut (dyn PartialReflect + Send + Sync)) { self.push_arg(ArgValue::Mut(arg)); } @@ -90,7 +90,7 @@ impl<'a> ArgList<'a> { /// /// If an argument was previously removed from the beginning of the list, /// this method will also re-index the list. - pub fn push_owned(&mut self, arg: impl PartialReflect) { + pub fn push_owned(&mut self, arg: impl PartialReflect + Send + Sync) { self.push_arg(ArgValue::Owned(Box::new(arg))); } @@ -98,7 +98,7 @@ impl<'a> ArgList<'a> { /// /// If an argument was previously removed from the beginning of the list, /// this method will also re-index the list. - pub fn push_boxed(&mut self, arg: Box) { + pub fn push_boxed(&mut self, arg: Box) { self.push_arg(ArgValue::Owned(arg)); } @@ -115,7 +115,7 @@ impl<'a> ArgList<'a> { /// /// If an argument was previously removed from the beginning of the list, /// this method will also re-index the list. - pub fn with_ref(self, arg: &'a dyn PartialReflect) -> Self { + pub fn with_ref(self, arg: &'a (dyn PartialReflect + Send + Sync)) -> Self { self.with_arg(ArgValue::Ref(arg)) } @@ -123,7 +123,7 @@ impl<'a> ArgList<'a> { /// /// If an argument was previously removed from the beginning of the list, /// this method will also re-index the list. - pub fn with_mut(self, arg: &'a mut dyn PartialReflect) -> Self { + pub fn with_mut(self, arg: &'a mut (dyn PartialReflect + Send + Sync)) -> Self { self.with_arg(ArgValue::Mut(arg)) } @@ -131,7 +131,7 @@ impl<'a> ArgList<'a> { /// /// If an argument was previously removed from the beginning of the list, /// this method will also re-index the list. - pub fn with_owned(self, arg: impl PartialReflect) -> Self { + pub fn with_owned(self, arg: impl PartialReflect + Send + Sync) -> Self { self.with_arg(ArgValue::Owned(Box::new(arg))) } @@ -139,7 +139,7 @@ impl<'a> ArgList<'a> { /// /// If an argument was previously removed from the beginning of the list, /// this method will also re-index the list. - pub fn with_boxed(self, arg: Box) -> Self { + pub fn with_boxed(self, arg: Box) -> Self { self.with_arg(ArgValue::Owned(arg)) } @@ -193,7 +193,7 @@ impl<'a> ArgList<'a> { /// let value = args.take_owned::().unwrap(); /// assert_eq!(value, 123); /// ``` - pub fn take_owned(&mut self) -> Result { + pub fn take_owned(&mut self) -> Result { self.take_arg()?.take_owned() } @@ -212,7 +212,7 @@ impl<'a> ArgList<'a> { /// let value = args.take_ref::().unwrap(); /// assert_eq!(*value, 123); /// ``` - pub fn take_ref(&mut self) -> Result<&'a T, ArgError> { + pub fn take_ref(&mut self) -> Result<&'a T, ArgError> { self.take_arg()?.take_ref() } @@ -231,7 +231,7 @@ impl<'a> ArgList<'a> { /// let value = args.take_mut::().unwrap(); /// assert_eq!(*value, 123); /// ``` - pub fn take_mut(&mut self) -> Result<&'a mut T, ArgError> { + pub fn take_mut(&mut self) -> Result<&'a mut T, ArgError> { self.take_arg()?.take_mut() } @@ -284,7 +284,7 @@ impl<'a> ArgList<'a> { /// let value = args.pop_owned::().unwrap(); /// assert_eq!(value, 123); /// ``` - pub fn pop_owned(&mut self) -> Result { + pub fn pop_owned(&mut self) -> Result { self.pop_arg()?.take_owned() } @@ -303,7 +303,7 @@ impl<'a> ArgList<'a> { /// let value = args.pop_ref::().unwrap(); /// assert_eq!(*value, 123); /// ``` - pub fn pop_ref(&mut self) -> Result<&'a T, ArgError> { + pub fn pop_ref(&mut self) -> Result<&'a T, ArgError> { self.pop_arg()?.take_ref() } @@ -322,7 +322,7 @@ impl<'a> ArgList<'a> { /// let value = args.pop_mut::().unwrap(); /// assert_eq!(*value, 123); /// ``` - pub fn pop_mut(&mut self) -> Result<&'a mut T, ArgError> { + pub fn pop_mut(&mut self) -> Result<&'a mut T, ArgError> { self.pop_arg()?.take_mut() } diff --git a/crates/bevy_reflect/src/func/dynamic_function.rs b/crates/bevy_reflect/src/func/dynamic_function.rs index 9253921112ffb..f06ec52aa6708 100644 --- a/crates/bevy_reflect/src/func/dynamic_function.rs +++ b/crates/bevy_reflect/src/func/dynamic_function.rs @@ -368,31 +368,33 @@ impl PartialReflect for DynamicFunction<'static> { None } - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Err(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { None } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { None } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { match value.reflect_ref() { ReflectRef::Function(func) => { *self = func.to_dynamic_function(); @@ -425,7 +427,7 @@ impl PartialReflect for DynamicFunction<'static> { None } - fn reflect_partial_eq(&self, _value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, _value: &(dyn PartialReflect + Send + Sync)) -> Option { None } diff --git a/crates/bevy_reflect/src/func/mod.rs b/crates/bevy_reflect/src/func/mod.rs index 74a89282c6d2d..ceb71d71af48d 100644 --- a/crates/bevy_reflect/src/func/mod.rs +++ b/crates/bevy_reflect/src/func/mod.rs @@ -27,7 +27,7 @@ //! // Pushing a known type with owned ownership //! .with_owned(25_i32) //! // Pushing a reflected type with owned ownership -//! .with_boxed(Box::new(75_i32) as Box); +//! .with_boxed(Box::new(75_i32) as Box); //! let result: FunctionResult = func.call(args); //! let value: Return = result.unwrap(); //! assert_eq!(value.unwrap_owned().try_downcast_ref::(), Some(&100)); diff --git a/crates/bevy_reflect/src/func/reflect_fn.rs b/crates/bevy_reflect/src/func/reflect_fn.rs index 6ef7c22eb177a..a9f3081a9d45b 100644 --- a/crates/bevy_reflect/src/func/reflect_fn.rs +++ b/crates/bevy_reflect/src/func/reflect_fn.rs @@ -116,7 +116,7 @@ macro_rules! impl_reflect_fn { // === (&self, ...) -> &ReturnType === // impl<'env, Receiver, $($Arg,)* ReturnType, Function> ReflectFn<'env, fn(&Receiver, $($Arg),*) -> &ReturnType> for Function where - Receiver: Reflect + TypePath, + Receiver: Reflect + Send + Sync + TypePath, $($Arg: FromArg,)* ReturnType: Reflect, // This clause allows us to convert `&ReturnType` into `Return` @@ -146,7 +146,7 @@ macro_rules! impl_reflect_fn { // === (&mut self, ...) -> &mut ReturnType === // impl<'env, Receiver, $($Arg,)* ReturnType, Function> ReflectFn<'env, fn(&mut Receiver, $($Arg),*) -> &mut ReturnType> for Function where - Receiver: Reflect + TypePath, + Receiver: Reflect + Send + Sync + TypePath, $($Arg: FromArg,)* ReturnType: Reflect, // This clause allows us to convert `&mut ReturnType` into `Return` @@ -176,7 +176,7 @@ macro_rules! impl_reflect_fn { // === (&mut self, ...) -> &ReturnType === // impl<'env, Receiver, $($Arg,)* ReturnType, Function> ReflectFn<'env, fn(&mut Receiver, $($Arg),*) -> &ReturnType> for Function where - Receiver: Reflect + TypePath, + Receiver: Reflect + Send + Sync + TypePath, $($Arg: FromArg,)* ReturnType: Reflect, // This clause allows us to convert `&ReturnType` into `Return` diff --git a/crates/bevy_reflect/src/func/reflect_fn_mut.rs b/crates/bevy_reflect/src/func/reflect_fn_mut.rs index 98db2b45907ef..bf8c38ecf6d09 100644 --- a/crates/bevy_reflect/src/func/reflect_fn_mut.rs +++ b/crates/bevy_reflect/src/func/reflect_fn_mut.rs @@ -123,7 +123,7 @@ macro_rules! impl_reflect_fn_mut { // === (&self, ...) -> &ReturnType === // impl<'env, Receiver, $($Arg,)* ReturnType, Function> ReflectFnMut<'env, fn(&Receiver, $($Arg),*) -> &ReturnType> for Function where - Receiver: Reflect + TypePath, + Receiver: Reflect + Send + Sync + TypePath, $($Arg: FromArg,)* ReturnType: Reflect, // This clause allows us to convert `&ReturnType` into `Return` @@ -153,7 +153,7 @@ macro_rules! impl_reflect_fn_mut { // === (&mut self, ...) -> &mut ReturnType === // impl<'env, Receiver, $($Arg,)* ReturnType, Function> ReflectFnMut<'env, fn(&mut Receiver, $($Arg),*) -> &mut ReturnType> for Function where - Receiver: Reflect + TypePath, + Receiver: Reflect + Send + Sync + TypePath, $($Arg: FromArg,)* ReturnType: Reflect, // This clause allows us to convert `&mut ReturnType` into `Return` @@ -183,7 +183,7 @@ macro_rules! impl_reflect_fn_mut { // === (&mut self, ...) -> &ReturnType === // impl<'env, Receiver, $($Arg,)* ReturnType, Function> ReflectFnMut<'env, fn(&mut Receiver, $($Arg),*) -> &ReturnType> for Function where - Receiver: Reflect + TypePath, + Receiver: Reflect + Send + Sync + TypePath, $($Arg: FromArg,)* ReturnType: Reflect, // This clause allows us to convert `&ReturnType` into `Return` diff --git a/crates/bevy_reflect/src/func/return_type.rs b/crates/bevy_reflect/src/func/return_type.rs index bab3c04b25962..441b57e197989 100644 --- a/crates/bevy_reflect/src/func/return_type.rs +++ b/crates/bevy_reflect/src/func/return_type.rs @@ -10,11 +10,11 @@ pub enum Return<'a> { /// The function returns an owned value. /// /// This includes functions that return nothing (i.e. they return `()`). - Owned(Box), + Owned(Box), /// The function returns a reference to a value. - Ref(&'a dyn PartialReflect), + Ref(&'a (dyn PartialReflect + Send + Sync)), /// The function returns a mutable reference to a value. - Mut(&'a mut dyn PartialReflect), + Mut(&'a mut (dyn PartialReflect + Send + Sync)), } impl<'a> Return<'a> { @@ -36,7 +36,7 @@ impl<'a> Return<'a> { /// # Panics /// /// Panics if the return value is not [`Self::Owned`]. - pub fn unwrap_owned(self) -> Box { + pub fn unwrap_owned(self) -> Box { match self { Return::Owned(value) => value, _ => panic!("expected owned value"), @@ -48,7 +48,7 @@ impl<'a> Return<'a> { /// # Panics /// /// Panics if the return value is not [`Self::Ref`]. - pub fn unwrap_ref(self) -> &'a dyn PartialReflect { + pub fn unwrap_ref(self) -> &'a (dyn PartialReflect + Send + Sync) { match self { Return::Ref(value) => value, _ => panic!("expected reference value"), @@ -60,7 +60,7 @@ impl<'a> Return<'a> { /// # Panics /// /// Panics if the return value is not [`Self::Mut`]. - pub fn unwrap_mut(self) -> &'a mut dyn PartialReflect { + pub fn unwrap_mut(self) -> &'a mut (dyn PartialReflect + Send + Sync) { match self { Return::Mut(value) => value, _ => panic!("expected mutable reference value"), diff --git a/crates/bevy_reflect/src/generics.rs b/crates/bevy_reflect/src/generics.rs index dfe21c6ec0843..8e2f2eb9d0826 100644 --- a/crates/bevy_reflect/src/generics.rs +++ b/crates/bevy_reflect/src/generics.rs @@ -166,7 +166,7 @@ pub struct ConstParamInfo { ty: Type, // Rust currently only allows certain primitive types in const generic position, // meaning that `Reflect` is guaranteed to be implemented for the default value. - default: Option>, + default: Option>, } impl ConstParamInfo { @@ -180,7 +180,7 @@ impl ConstParamInfo { } /// Sets the default value for the parameter. - pub fn with_default(mut self, default: T) -> Self { + pub fn with_default(mut self, default: T) -> Self { let arc = Arc::new(default); #[cfg(not(target_has_atomic = "ptr"))] @@ -191,7 +191,8 @@ impl ConstParamInfo { // SAFETY: // - Coercion from `T` to `dyn Reflect` is valid as `T: Reflect + 'static` // - `Arc::from_raw` receives a valid pointer from a previous call to `Arc::into_raw` - let arc = unsafe { Arc::from_raw(Arc::into_raw(arc) as *const dyn Reflect) }; + let arc = + unsafe { Arc::from_raw(Arc::into_raw(arc) as *const (dyn Reflect + Send + Sync)) }; self.default = Some(arc); self @@ -220,7 +221,7 @@ impl ConstParamInfo { /// /// assert_eq!(default.downcast_ref::().unwrap(), &10); /// ``` - pub fn default(&self) -> Option<&dyn Reflect> { + pub fn default(&self) -> Option<&(dyn Reflect + Send + Sync)> { self.default.as_deref() } diff --git a/crates/bevy_reflect/src/impls/smallvec.rs b/crates/bevy_reflect/src/impls/smallvec.rs index 942bcbe83f17c..939608751c179 100644 --- a/crates/bevy_reflect/src/impls/smallvec.rs +++ b/crates/bevy_reflect/src/impls/smallvec.rs @@ -12,25 +12,25 @@ use smallvec::{Array as SmallArray, SmallVec}; impl List for SmallVec where - T::Item: FromReflect + MaybeTyped + TypePath, + T::Item: FromReflect + Send + Sync + MaybeTyped + TypePath, { - fn get(&self, index: usize) -> Option<&dyn PartialReflect> { + fn get(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)> { if index < SmallVec::len(self) { - Some(&self[index] as &dyn PartialReflect) + Some(&self[index] as &(dyn PartialReflect + Send + Sync)) } else { None } } - fn get_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect> { + fn get_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)> { if index < SmallVec::len(self) { - Some(&mut self[index] as &mut dyn PartialReflect) + Some(&mut self[index] as &mut (dyn PartialReflect + Send + Sync)) } else { None } } - fn insert(&mut self, index: usize, value: Box) { + fn insert(&mut self, index: usize, value: Box) { let value = value.try_take::().unwrap_or_else(|value| { ::Item::from_reflect(&*value).unwrap_or_else(|| { panic!( @@ -42,11 +42,11 @@ where SmallVec::insert(self, index, value); } - fn remove(&mut self, index: usize) -> Box { + fn remove(&mut self, index: usize) -> Box { Box::new(self.remove(index)) } - fn push(&mut self, value: Box) { + fn push(&mut self, value: Box) { let value = value.try_take::().unwrap_or_else(|value| { ::Item::from_reflect(&*value).unwrap_or_else(|| { panic!( @@ -58,9 +58,9 @@ where SmallVec::push(self, value); } - fn pop(&mut self) -> Option> { + fn pop(&mut self) -> Option> { self.pop() - .map(|value| Box::new(value) as Box) + .map(|value| Box::new(value) as Box) } fn len(&self) -> usize { @@ -71,50 +71,52 @@ where ListIter::new(self) } - fn drain(&mut self) -> Vec> { + fn drain(&mut self) -> Vec> { self.drain(..) - .map(|value| Box::new(value) as Box) + .map(|value| Box::new(value) as Box) .collect() } } impl PartialReflect for SmallVec where - T::Item: FromReflect + MaybeTyped + TypePath, + T::Item: FromReflect + Send + Sync + MaybeTyped + TypePath, { fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { Some(::type_info()) } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { crate::list_apply(self, value); } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { crate::list_try_apply(self, value) } @@ -134,7 +136,7 @@ where ReflectOwned::List(self) } - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { Ok(Box::new( self.iter() .map(|value| { @@ -150,14 +152,14 @@ where )) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { crate::list_partial_eq(self, value) } } impl Reflect for SmallVec where - T::Item: FromReflect + MaybeTyped + TypePath, + T::Item: FromReflect + Send + Sync + MaybeTyped + TypePath, { fn into_any(self: Box) -> Box { self @@ -171,19 +173,22 @@ where self } - fn into_reflect(self: Box) -> Box { + fn into_reflect(self: Box) -> Box { self } - fn as_reflect(&self) -> &dyn Reflect { + fn as_reflect(&self) -> &(dyn Reflect + Send + Sync) { self } - fn as_reflect_mut(&mut self) -> &mut dyn Reflect { + fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + Send + Sync) { self } - fn set(&mut self, value: Box) -> Result<(), Box> { + fn set( + &mut self, + value: Box, + ) -> Result<(), Box> { *self = value.take()?; Ok(()) } @@ -191,7 +196,7 @@ where impl Typed for SmallVec where - T::Item: FromReflect + MaybeTyped + TypePath, + T::Item: FromReflect + Send + Sync + MaybeTyped + TypePath, { fn type_info() -> &'static TypeInfo { static CELL: GenericTypeInfoCell = GenericTypeInfoCell::new(); @@ -208,9 +213,9 @@ impl_type_path!(::smallvec::SmallVec); impl FromReflect for SmallVec where - T::Item: FromReflect + MaybeTyped + TypePath, + T::Item: FromReflect + Send + Sync + MaybeTyped + TypePath, { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { let ref_list = reflect.reflect_ref().as_list().ok()?; let mut new_list = Self::with_capacity(ref_list.len()); @@ -225,7 +230,7 @@ where impl GetTypeRegistration for SmallVec where - T::Item: FromReflect + MaybeTyped + TypePath, + T::Item: FromReflect + Send + Sync + MaybeTyped + TypePath, { fn get_type_registration() -> TypeRegistration { let mut registration = TypeRegistration::of::>(); @@ -235,4 +240,4 @@ where } #[cfg(feature = "functions")] -crate::func::macros::impl_function_traits!(SmallVec; where T::Item: FromReflect + MaybeTyped + TypePath); +crate::func::macros::impl_function_traits!(SmallVec; where T::Item: FromReflect + Send + Sync + MaybeTyped + TypePath); diff --git a/crates/bevy_reflect/src/impls/smol_str.rs b/crates/bevy_reflect/src/impls/smol_str.rs index d07a00cd6f656..26d71eecad211 100644 --- a/crates/bevy_reflect/src/impls/smol_str.rs +++ b/crates/bevy_reflect/src/impls/smol_str.rs @@ -18,9 +18,9 @@ mod tests { #[test] fn should_partial_eq_smolstr() { - let a: &dyn PartialReflect = &SmolStr::new("A"); - let a2: &dyn PartialReflect = &SmolStr::new("A"); - let b: &dyn PartialReflect = &SmolStr::new("B"); + let a: &(dyn PartialReflect + Send + Sync) = &SmolStr::new("A"); + let a2: &(dyn PartialReflect + Send + Sync) = &SmolStr::new("A"); + let b: &(dyn PartialReflect + Send + Sync) = &SmolStr::new("B"); assert_eq!(Some(true), a.reflect_partial_eq(a2)); assert_eq!(Some(false), a.reflect_partial_eq(b)); } diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index 4be1521b7ec6d..533c13bfae546 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -383,39 +383,39 @@ macro_rules! impl_reflect_for_atomic { Some(::type_info()) } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } #[inline] - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } #[inline] - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } #[inline] fn try_into_reflect( self: Box, - ) -> Result, Box> { + ) -> Result, Box> { Ok(self) } #[inline] - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } #[inline] - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } #[inline] - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { Ok(Box::new(<$ty>::new(self.load($ordering)))) } #[inline] - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { if let Some(value) = value.try_downcast_ref::() { *self = <$ty>::new(value.load($ordering)); } else { @@ -451,7 +451,7 @@ macro_rules! impl_reflect_for_atomic { where $ty: Any + Send + Sync, { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { Some(<$ty>::new( reflect.try_downcast_ref::<$ty>()?.load($ordering), )) @@ -512,18 +512,18 @@ impl_reflect_for_atomic!( macro_rules! impl_reflect_for_veclike { ($ty:ty, $insert:expr, $remove:expr, $push:expr, $pop:expr, $sub:ty) => { - impl List for $ty { + impl List for $ty { #[inline] - fn get(&self, index: usize) -> Option<&dyn PartialReflect> { - <$sub>::get(self, index).map(|value| value as &dyn PartialReflect) + fn get(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)> { + <$sub>::get(self, index).map(|value| value as &(dyn PartialReflect + Send + Sync)) } #[inline] - fn get_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect> { - <$sub>::get_mut(self, index).map(|value| value as &mut dyn PartialReflect) + fn get_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)> { + <$sub>::get_mut(self, index).map(|value| value as &mut (dyn PartialReflect + Send + Sync)) } - fn insert(&mut self, index: usize, value: Box) { + fn insert(&mut self, index: usize, value: Box) { let value = value.try_take::().unwrap_or_else(|value| { T::from_reflect(&*value).unwrap_or_else(|| { panic!( @@ -535,11 +535,11 @@ macro_rules! impl_reflect_for_veclike { $insert(self, index, value); } - fn remove(&mut self, index: usize) -> Box { + fn remove(&mut self, index: usize) -> Box { Box::new($remove(self, index)) } - fn push(&mut self, value: Box) { + fn push(&mut self, value: Box) { let value = T::take_from_reflect(value).unwrap_or_else(|value| { panic!( "Attempted to push invalid value of type {}.", @@ -549,8 +549,8 @@ macro_rules! impl_reflect_for_veclike { $push(self, value); } - fn pop(&mut self) -> Option> { - $pop(self).map(|value| Box::new(value) as Box) + fn pop(&mut self) -> Option> { + $pop(self).map(|value| Box::new(value) as Box) } #[inline] @@ -564,44 +564,44 @@ macro_rules! impl_reflect_for_veclike { } #[inline] - fn drain(&mut self) -> Vec> { + fn drain(&mut self) -> Vec> { self.drain(..) - .map(|value| Box::new(value) as Box) + .map(|value| Box::new(value) as Box) .collect() } } - impl PartialReflect for $ty { + impl PartialReflect for $ty { #[inline] fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { Some(::type_info()) } - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } #[inline] - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } #[inline] - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } fn try_into_reflect( self: Box, - ) -> Result, Box> { + ) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } @@ -621,7 +621,7 @@ macro_rules! impl_reflect_for_veclike { ReflectOwned::List(self) } - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { Ok(Box::new( self.iter() .map(|value| { @@ -640,22 +640,22 @@ macro_rules! impl_reflect_for_veclike { crate::list_hash(self) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { crate::list_partial_eq(self, value) } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { crate::list_apply(self, value); } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { crate::list_try_apply(self, value) } } - impl_full_reflect!( for $ty where T: FromReflect + MaybeTyped + TypePath + GetTypeRegistration); + impl_full_reflect!( for $ty where T: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration); - impl Typed for $ty { + impl Typed for $ty { fn type_info() -> &'static TypeInfo { static CELL: GenericTypeInfoCell = GenericTypeInfoCell::new(); CELL.get_or_insert::(|| { @@ -668,7 +668,7 @@ macro_rules! impl_reflect_for_veclike { } } - impl GetTypeRegistration + impl GetTypeRegistration for $ty { fn get_type_registration() -> TypeRegistration { @@ -683,8 +683,8 @@ macro_rules! impl_reflect_for_veclike { } } - impl FromReflect for $ty { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + impl FromReflect for $ty { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { let ref_list = reflect.reflect_ref().as_list().ok()?; let mut new_list = Self::with_capacity(ref_list.len()); @@ -702,7 +702,7 @@ macro_rules! impl_reflect_for_veclike { impl_reflect_for_veclike!(Vec, Vec::insert, Vec::remove, Vec::push, Vec::pop, [T]); impl_type_path!(::alloc::vec::Vec); #[cfg(feature = "functions")] -crate::func::macros::impl_function_traits!(Vec; ); +crate::func::macros::impl_function_traits!(Vec; ); impl_reflect_for_veclike!( VecDeque, @@ -714,40 +714,40 @@ impl_reflect_for_veclike!( ); impl_type_path!(::alloc::collections::VecDeque); #[cfg(feature = "functions")] -crate::func::macros::impl_function_traits!(VecDeque; ); +crate::func::macros::impl_function_traits!(VecDeque; ); macro_rules! impl_reflect_for_hashmap { ($ty:path) => { impl Map for $ty where - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, S: TypePath + BuildHasher + Default + Send + Sync, { - fn get(&self, key: &dyn PartialReflect) -> Option<&dyn PartialReflect> { + fn get(&self, key: &(dyn PartialReflect + Send + Sync)) -> Option<&(dyn PartialReflect + Send + Sync)> { key.try_downcast_ref::() .and_then(|key| Self::get(self, key)) - .map(|value| value as &dyn PartialReflect) + .map(|value| value as &(dyn PartialReflect + Send + Sync)) } - fn get_mut(&mut self, key: &dyn PartialReflect) -> Option<&mut dyn PartialReflect> { + fn get_mut(&mut self, key: &(dyn PartialReflect + Send + Sync)) -> Option<&mut (dyn PartialReflect + Send + Sync)> { key.try_downcast_ref::() .and_then(move |key| Self::get_mut(self, key)) - .map(|value| value as &mut dyn PartialReflect) + .map(|value| value as &mut (dyn PartialReflect + Send + Sync)) } - fn get_at(&self, index: usize) -> Option<(&dyn PartialReflect, &dyn PartialReflect)> { + fn get_at(&self, index: usize) -> Option<(&(dyn PartialReflect + Send + Sync), &(dyn PartialReflect + Send + Sync))> { self.iter() .nth(index) - .map(|(key, value)| (key as &dyn PartialReflect, value as &dyn PartialReflect)) + .map(|(key, value)| (key as &(dyn PartialReflect + Send + Sync), value as &(dyn PartialReflect + Send + Sync))) } fn get_at_mut( &mut self, index: usize, - ) -> Option<(&dyn PartialReflect, &mut dyn PartialReflect)> { + ) -> Option<(&(dyn PartialReflect + Send + Sync), &mut (dyn PartialReflect + Send + Sync))> { self.iter_mut().nth(index).map(|(key, value)| { - (key as &dyn PartialReflect, value as &mut dyn PartialReflect) + (key as &(dyn PartialReflect + Send + Sync), value as &mut (dyn PartialReflect + Send + Sync)) }) } @@ -759,12 +759,12 @@ macro_rules! impl_reflect_for_hashmap { MapIter::new(self) } - fn drain(&mut self) -> Vec<(Box, Box)> { + fn drain(&mut self) -> Vec<(Box, Box)> { self.drain() .map(|(key, value)| { ( - Box::new(key) as Box, - Box::new(value) as Box, + Box::new(key) as Box, + Box::new(value) as Box, ) }) .collect() @@ -787,9 +787,9 @@ macro_rules! impl_reflect_for_hashmap { fn insert_boxed( &mut self, - key: Box, - value: Box, - ) -> Option> { + key: Box, + value: Box, + ) -> Option> { let key = K::take_from_reflect(key).unwrap_or_else(|key| { panic!( "Attempted to insert invalid key of type {}.", @@ -803,10 +803,10 @@ macro_rules! impl_reflect_for_hashmap { ) }); self.insert(key, value) - .map(|old_value| Box::new(old_value) as Box) + .map(|old_value| Box::new(old_value) as Box) } - fn remove(&mut self, key: &dyn PartialReflect) -> Option> { + fn remove(&mut self, key: &(dyn PartialReflect + Send + Sync)) -> Option> { let mut from_reflect = None; key.try_downcast_ref::() .or_else(|| { @@ -814,14 +814,14 @@ macro_rules! impl_reflect_for_hashmap { from_reflect.as_ref() }) .and_then(|key| self.remove(key)) - .map(|value| Box::new(value) as Box) + .map(|value| Box::new(value) as Box) } } impl PartialReflect for $ty where - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, S: TypePath + BuildHasher + Default + Send + Sync, { fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { @@ -829,29 +829,29 @@ macro_rules! impl_reflect_for_hashmap { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } fn try_into_reflect( self: Box, - ) -> Result, Box> { + ) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } @@ -871,7 +871,7 @@ macro_rules! impl_reflect_for_hashmap { ReflectOwned::Map(self) } - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { let mut map = Self::with_capacity_and_hasher(self.len(), S::default()); for (key, value) in self.iter() { let key = key.reflect_clone()?.take().map_err(|_| { @@ -892,15 +892,15 @@ macro_rules! impl_reflect_for_hashmap { Ok(Box::new(map)) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { map_partial_eq(self, value) } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { map_apply(self, value); } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { map_try_apply(self, value) } } @@ -908,15 +908,15 @@ macro_rules! impl_reflect_for_hashmap { impl_full_reflect!( for $ty where - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, S: TypePath + BuildHasher + Default + Send + Sync, ); impl Typed for $ty where - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, S: TypePath + BuildHasher + Default + Send + Sync, { fn type_info() -> &'static TypeInfo { @@ -934,8 +934,8 @@ macro_rules! impl_reflect_for_hashmap { impl GetTypeRegistration for $ty where - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, S: TypePath + BuildHasher + Default + Send + Sync + Default, { fn get_type_registration() -> TypeRegistration { @@ -953,11 +953,11 @@ macro_rules! impl_reflect_for_hashmap { impl FromReflect for $ty where - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, S: TypePath + BuildHasher + Default + Send + Sync, { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { let ref_map = reflect.reflect_ref().as_map().ok()?; let mut new_map = Self::with_capacity_and_hasher(ref_map.len(), S::default()); @@ -984,8 +984,8 @@ impl_type_path!(::std::collections::HashMap); #[cfg(all(feature = "functions", feature = "std"))] crate::func::macros::impl_function_traits!(::std::collections::HashMap; < - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, S: TypePath + BuildHasher + Default + Send + Sync > ); @@ -995,8 +995,8 @@ impl_type_path!(::bevy_platform_support::collections::HashMap); #[cfg(feature = "functions")] crate::func::macros::impl_function_traits!(::bevy_platform_support::collections::HashMap; < - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, S: TypePath + BuildHasher + Default + Send + Sync > ); @@ -1005,32 +1005,32 @@ macro_rules! impl_reflect_for_hashset { ($ty:path) => { impl Set for $ty where - V: FromReflect + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + TypePath + GetTypeRegistration + Eq + Hash, S: TypePath + BuildHasher + Default + Send + Sync, { - fn get(&self, value: &dyn PartialReflect) -> Option<&dyn PartialReflect> { + fn get(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option<&(dyn PartialReflect + Send + Sync)> { value .try_downcast_ref::() .and_then(|value| Self::get(self, value)) - .map(|value| value as &dyn PartialReflect) + .map(|value| value as &(dyn PartialReflect + Send + Sync)) } fn len(&self) -> usize { Self::len(self) } - fn iter(&self) -> Box + '_> { - let iter = self.iter().map(|v| v as &dyn PartialReflect); + fn iter(&self) -> Box + '_> { + let iter = self.iter().map(|v| v as &(dyn PartialReflect + Send + Sync)); Box::new(iter) } - fn drain(&mut self) -> Vec> { + fn drain(&mut self) -> Vec> { self.drain() - .map(|value| Box::new(value) as Box) + .map(|value| Box::new(value) as Box) .collect() } - fn insert_boxed(&mut self, value: Box) -> bool { + fn insert_boxed(&mut self, value: Box) -> bool { let value = V::take_from_reflect(value).unwrap_or_else(|value| { panic!( "Attempted to insert invalid value of type {}.", @@ -1040,7 +1040,7 @@ macro_rules! impl_reflect_for_hashset { self.insert(value) } - fn remove(&mut self, value: &dyn PartialReflect) -> bool { + fn remove(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> bool { let mut from_reflect = None; value .try_downcast_ref::() @@ -1051,7 +1051,7 @@ macro_rules! impl_reflect_for_hashset { .is_some_and(|value| self.remove(value)) } - fn contains(&self, value: &dyn PartialReflect) -> bool { + fn contains(&self, value: &(dyn PartialReflect + Send + Sync)) -> bool { let mut from_reflect = None; value .try_downcast_ref::() @@ -1065,7 +1065,7 @@ macro_rules! impl_reflect_for_hashset { impl PartialReflect for $ty where - V: FromReflect + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + TypePath + GetTypeRegistration + Eq + Hash, S: TypePath + BuildHasher + Default + Send + Sync, { fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { @@ -1073,38 +1073,38 @@ macro_rules! impl_reflect_for_hashset { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } #[inline] fn try_into_reflect( self: Box, - ) -> Result, Box> { + ) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { set_apply(self, value); } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { set_try_apply(self, value) } @@ -1124,7 +1124,7 @@ macro_rules! impl_reflect_for_hashset { ReflectOwned::Set(self) } - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { let mut set = Self::with_capacity_and_hasher(self.len(), S::default()); for value in self.iter() { let value = value.reflect_clone()?.take().map_err(|_| { @@ -1139,14 +1139,14 @@ macro_rules! impl_reflect_for_hashset { Ok(Box::new(set)) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { set_partial_eq(self, value) } } impl Typed for $ty where - V: FromReflect + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + TypePath + GetTypeRegistration + Eq + Hash, S: TypePath + BuildHasher + Default + Send + Sync, { fn type_info() -> &'static TypeInfo { @@ -1163,7 +1163,7 @@ macro_rules! impl_reflect_for_hashset { impl GetTypeRegistration for $ty where - V: FromReflect + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + TypePath + GetTypeRegistration + Eq + Hash, S: TypePath + BuildHasher + Default + Send + Sync + Default, { fn get_type_registration() -> TypeRegistration { @@ -1181,16 +1181,16 @@ macro_rules! impl_reflect_for_hashset { impl_full_reflect!( for $ty where - V: FromReflect + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + TypePath + GetTypeRegistration + Eq + Hash, S: TypePath + BuildHasher + Default + Send + Sync, ); impl FromReflect for $ty where - V: FromReflect + TypePath + GetTypeRegistration + Eq + Hash, + V: FromReflect + Send + Sync + TypePath + GetTypeRegistration + Eq + Hash, S: TypePath + BuildHasher + Default + Send + Sync, { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { let ref_set = reflect.reflect_ref().as_set().ok()?; let mut new_set = Self::with_capacity_and_hasher(ref_set.len(), S::default()); @@ -1224,7 +1224,7 @@ impl_type_path!(::std::collections::HashSet); #[cfg(all(feature = "functions", feature = "std"))] crate::func::macros::impl_function_traits!(::std::collections::HashSet; < - V: Hash + Eq + FromReflect + TypePath + GetTypeRegistration, + V: Hash + Eq + FromReflect + Send + Sync + TypePath + GetTypeRegistration, S: TypePath + BuildHasher + Default + Send + Sync > ); @@ -1234,41 +1234,62 @@ impl_type_path!(::bevy_platform_support::collections::HashSet); #[cfg(feature = "functions")] crate::func::macros::impl_function_traits!(::bevy_platform_support::collections::HashSet; < - V: Hash + Eq + FromReflect + TypePath + GetTypeRegistration, + V: Hash + Eq + FromReflect + Send + Sync + TypePath + GetTypeRegistration, S: TypePath + BuildHasher + Default + Send + Sync > ); impl Map for ::alloc::collections::BTreeMap where - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, { - fn get(&self, key: &dyn PartialReflect) -> Option<&dyn PartialReflect> { + fn get( + &self, + key: &(dyn PartialReflect + Send + Sync), + ) -> Option<&(dyn PartialReflect + Send + Sync)> { key.try_downcast_ref::() .and_then(|key| Self::get(self, key)) - .map(|value| value as &dyn PartialReflect) + .map(|value| value as &(dyn PartialReflect + Send + Sync)) } - fn get_mut(&mut self, key: &dyn PartialReflect) -> Option<&mut dyn PartialReflect> { + fn get_mut( + &mut self, + key: &(dyn PartialReflect + Send + Sync), + ) -> Option<&mut (dyn PartialReflect + Send + Sync)> { key.try_downcast_ref::() .and_then(move |key| Self::get_mut(self, key)) - .map(|value| value as &mut dyn PartialReflect) + .map(|value| value as &mut (dyn PartialReflect + Send + Sync)) } - fn get_at(&self, index: usize) -> Option<(&dyn PartialReflect, &dyn PartialReflect)> { - self.iter() - .nth(index) - .map(|(key, value)| (key as &dyn PartialReflect, value as &dyn PartialReflect)) + fn get_at( + &self, + index: usize, + ) -> Option<( + &(dyn PartialReflect + Send + Sync), + &(dyn PartialReflect + Send + Sync), + )> { + self.iter().nth(index).map(|(key, value)| { + ( + key as &(dyn PartialReflect + Send + Sync), + value as &(dyn PartialReflect + Send + Sync), + ) + }) } fn get_at_mut( &mut self, index: usize, - ) -> Option<(&dyn PartialReflect, &mut dyn PartialReflect)> { - self.iter_mut() - .nth(index) - .map(|(key, value)| (key as &dyn PartialReflect, value as &mut dyn PartialReflect)) + ) -> Option<( + &(dyn PartialReflect + Send + Sync), + &mut (dyn PartialReflect + Send + Sync), + )> { + self.iter_mut().nth(index).map(|(key, value)| { + ( + key as &(dyn PartialReflect + Send + Sync), + value as &mut (dyn PartialReflect + Send + Sync), + ) + }) } fn len(&self) -> usize { @@ -1279,15 +1300,20 @@ where MapIter::new(self) } - fn drain(&mut self) -> Vec<(Box, Box)> { + fn drain( + &mut self, + ) -> Vec<( + Box, + Box, + )> { // BTreeMap doesn't have a `drain` function. See // https://github.com/rust-lang/rust/issues/81074. So we have to fake one by popping // elements off one at a time. let mut result = Vec::with_capacity(self.len()); while let Some((k, v)) = self.pop_first() { result.push(( - Box::new(k) as Box, - Box::new(v) as Box, + Box::new(k) as Box, + Box::new(v) as Box, )); } result @@ -1310,9 +1336,9 @@ where fn insert_boxed( &mut self, - key: Box, - value: Box, - ) -> Option> { + key: Box, + value: Box, + ) -> Option> { let key = K::take_from_reflect(key).unwrap_or_else(|key| { panic!( "Attempted to insert invalid key of type {}.", @@ -1326,10 +1352,13 @@ where ) }); self.insert(key, value) - .map(|old_value| Box::new(old_value) as Box) + .map(|old_value| Box::new(old_value) as Box) } - fn remove(&mut self, key: &dyn PartialReflect) -> Option> { + fn remove( + &mut self, + key: &(dyn PartialReflect + Send + Sync), + ) -> Option> { let mut from_reflect = None; key.try_downcast_ref::() .or_else(|| { @@ -1337,40 +1366,42 @@ where from_reflect.as_ref() }) .and_then(|key| self.remove(key)) - .map(|value| Box::new(value) as Box) + .map(|value| Box::new(value) as Box) } } impl PartialReflect for ::alloc::collections::BTreeMap where - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, { fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { Some(::type_info()) } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } #[inline] - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } fn reflect_kind(&self) -> ReflectKind { @@ -1389,7 +1420,7 @@ where ReflectOwned::Map(self) } - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { let mut map = Self::new(); for (key, value) in self.iter() { let key = @@ -1413,15 +1444,15 @@ where Ok(Box::new(map)) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { map_partial_eq(self, value) } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { map_apply(self, value); } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { map_try_apply(self, value) } } @@ -1429,14 +1460,14 @@ where impl_full_reflect!( for ::alloc::collections::BTreeMap where - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, ); impl Typed for ::alloc::collections::BTreeMap where - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, { fn type_info() -> &'static TypeInfo { static CELL: GenericTypeInfoCell = GenericTypeInfoCell::new(); @@ -1453,8 +1484,8 @@ where impl GetTypeRegistration for ::alloc::collections::BTreeMap where - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, { fn get_type_registration() -> TypeRegistration { let mut registration = TypeRegistration::of::(); @@ -1466,10 +1497,10 @@ where impl FromReflect for ::alloc::collections::BTreeMap where - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { let ref_map = reflect.reflect_ref().as_map().ok()?; let mut new_map = Self::new(); @@ -1488,20 +1519,22 @@ impl_type_path!(::alloc::collections::BTreeMap); #[cfg(feature = "functions")] crate::func::macros::impl_function_traits!(::alloc::collections::BTreeMap; < - K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, - V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + K: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, + V: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration > ); -impl Array for [T; N] { +impl Array + for [T; N] +{ #[inline] - fn get(&self, index: usize) -> Option<&dyn PartialReflect> { - <[T]>::get(self, index).map(|value| value as &dyn PartialReflect) + fn get(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)> { + <[T]>::get(self, index).map(|value| value as &(dyn PartialReflect + Send + Sync)) } #[inline] - fn get_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect> { - <[T]>::get_mut(self, index).map(|value| value as &mut dyn PartialReflect) + fn get_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)> { + <[T]>::get_mut(self, index).map(|value| value as &mut (dyn PartialReflect + Send + Sync)) } #[inline] @@ -1515,42 +1548,44 @@ impl A } #[inline] - fn drain(self: Box) -> Vec> { + fn drain(self: Box) -> Vec> { self.into_iter() - .map(|value| Box::new(value) as Box) + .map(|value| Box::new(value) as Box) .collect() } } -impl PartialReflect - for [T; N] +impl + PartialReflect for [T; N] { fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { Some(::type_info()) } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } @@ -1580,21 +1615,23 @@ impl P } #[inline] - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { crate::array_partial_eq(self, value) } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { crate::array_apply(self, value); } #[inline] - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { crate::array_try_apply(self, value) } } -impl Reflect for [T; N] { +impl Reflect + for [T; N] +{ #[inline] fn into_any(self: Box) -> Box { self @@ -1611,31 +1648,36 @@ impl R } #[inline] - fn into_reflect(self: Box) -> Box { + fn into_reflect(self: Box) -> Box { self } #[inline] - fn as_reflect(&self) -> &dyn Reflect { + fn as_reflect(&self) -> &(dyn Reflect + Send + Sync) { self } #[inline] - fn as_reflect_mut(&mut self) -> &mut dyn Reflect { + fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + Send + Sync) { self } #[inline] - fn set(&mut self, value: Box) -> Result<(), Box> { + fn set( + &mut self, + value: Box, + ) -> Result<(), Box> { *self = value.take()?; Ok(()) } } -impl FromReflect - for [T; N] +impl< + T: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration, + const N: usize, + > FromReflect for [T; N] { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { let ref_array = reflect.reflect_ref().as_array().ok()?; let mut temp_vec = Vec::with_capacity(ref_array.len()); @@ -1648,7 +1690,9 @@ impl Typed for [T; N] { +impl Typed + for [T; N] +{ fn type_info() -> &'static TypeInfo { static CELL: GenericTypeInfoCell = GenericTypeInfoCell::new(); CELL.get_or_insert::(|| TypeInfo::Array(ArrayInfo::new::(N))) @@ -1667,8 +1711,8 @@ impl TypePath for [T; N] { } } -impl GetTypeRegistration - for [T; N] +impl + GetTypeRegistration for [T; N] { fn get_type_registration() -> TypeRegistration { TypeRegistration::of::<[T; N]>() @@ -1680,7 +1724,7 @@ impl G } #[cfg(feature = "functions")] -crate::func::macros::impl_function_traits!([T; N]; [const N: usize]); +crate::func::macros::impl_function_traits!([T; N]; [const N: usize]); impl_reflect! { #[type_path = "core::option"] @@ -1728,27 +1772,29 @@ impl PartialReflect for Cow<'static, str> { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } @@ -1768,7 +1814,7 @@ impl PartialReflect for Cow<'static, str> { ReflectOwned::Opaque(self) } - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { Ok(Box::new(self.clone())) } @@ -1779,7 +1825,7 @@ impl PartialReflect for Cow<'static, str> { Some(hasher.finish()) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { if let Some(value) = value.try_downcast_ref::() { Some(PartialEq::eq(self, value)) } else { @@ -1791,7 +1837,7 @@ impl PartialReflect for Cow<'static, str> { fmt::Debug::fmt(self, f) } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { if let Some(value) = value.try_downcast_ref::() { self.clone_from(value); } else { @@ -1826,7 +1872,7 @@ impl GetTypeRegistration for Cow<'static, str> { } impl FromReflect for Cow<'static, str> { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { Some(reflect.try_downcast_ref::>()?.clone()) } } @@ -1849,20 +1895,22 @@ where } } -impl List +impl List for Cow<'static, [T]> { - fn get(&self, index: usize) -> Option<&dyn PartialReflect> { - self.as_ref().get(index).map(|x| x as &dyn PartialReflect) + fn get(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)> { + self.as_ref() + .get(index) + .map(|x| x as &(dyn PartialReflect + Send + Sync)) } - fn get_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect> { + fn get_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)> { self.to_mut() .get_mut(index) - .map(|x| x as &mut dyn PartialReflect) + .map(|x| x as &mut (dyn PartialReflect + Send + Sync)) } - fn insert(&mut self, index: usize, element: Box) { + fn insert(&mut self, index: usize, element: Box) { let value = T::take_from_reflect(element).unwrap_or_else(|value| { panic!( "Attempted to insert invalid value of type {}.", @@ -1872,11 +1920,11 @@ impl List self.to_mut().insert(index, value); } - fn remove(&mut self, index: usize) -> Box { + fn remove(&mut self, index: usize) -> Box { Box::new(self.to_mut().remove(index)) } - fn push(&mut self, value: Box) { + fn push(&mut self, value: Box) { let value = T::take_from_reflect(value).unwrap_or_else(|value| { panic!( "Attempted to push invalid value of type {}.", @@ -1886,10 +1934,10 @@ impl List self.to_mut().push(value); } - fn pop(&mut self) -> Option> { + fn pop(&mut self) -> Option> { self.to_mut() .pop() - .map(|value| Box::new(value) as Box) + .map(|value| Box::new(value) as Box) } fn len(&self) -> usize { @@ -1900,43 +1948,45 @@ impl List ListIter::new(self) } - fn drain(&mut self) -> Vec> { + fn drain(&mut self) -> Vec> { self.to_mut() .drain(..) - .map(|value| Box::new(value) as Box) + .map(|value| Box::new(value) as Box) .collect() } } -impl PartialReflect - for Cow<'static, [T]> +impl + PartialReflect for Cow<'static, [T]> { fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { Some(::type_info()) } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } @@ -1956,7 +2006,7 @@ impl Parti ReflectOwned::List(self) } - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { Ok(Box::new(self.clone())) } @@ -1964,15 +2014,15 @@ impl Parti crate::list_hash(self) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { crate::list_partial_eq(self, value) } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { crate::list_apply(self, value); } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { crate::list_try_apply(self, value) } } @@ -1980,10 +2030,10 @@ impl Parti impl_full_reflect!( for Cow<'static, [T]> where - T: FromReflect + Clone + MaybeTyped + TypePath + GetTypeRegistration, + T: FromReflect + Send + Sync + Clone + MaybeTyped + TypePath + GetTypeRegistration, ); -impl Typed +impl Typed for Cow<'static, [T]> { fn type_info() -> &'static TypeInfo { @@ -1992,8 +2042,8 @@ impl Typed } } -impl GetTypeRegistration - for Cow<'static, [T]> +impl + GetTypeRegistration for Cow<'static, [T]> { fn get_type_registration() -> TypeRegistration { TypeRegistration::of::>() @@ -2004,10 +2054,10 @@ impl GetTy } } -impl FromReflect +impl FromReflect for Cow<'static, [T]> { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { let ref_list = reflect.reflect_ref().as_list().ok()?; let mut temp_vec = Vec::with_capacity(ref_list.len()); @@ -2021,7 +2071,7 @@ impl FromR } #[cfg(feature = "functions")] -crate::func::macros::impl_function_traits!(Cow<'static, [T]>; ); +crate::func::macros::impl_function_traits!(Cow<'static, [T]>; ); impl PartialReflect for &'static str { fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { @@ -2029,27 +2079,29 @@ impl PartialReflect for &'static str { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } @@ -2065,7 +2117,7 @@ impl PartialReflect for &'static str { ReflectOwned::Opaque(self) } - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { Ok(Box::new(*self)) } @@ -2076,7 +2128,7 @@ impl PartialReflect for &'static str { Some(hasher.finish()) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { if let Some(value) = value.try_downcast_ref::() { Some(PartialEq::eq(self, value)) } else { @@ -2088,7 +2140,7 @@ impl PartialReflect for &'static str { fmt::Debug::fmt(&self, f) } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { if let Some(value) = value.try_downcast_ref::() { self.clone_from(value); } else { @@ -2114,19 +2166,22 @@ impl Reflect for &'static str { self } - fn into_reflect(self: Box) -> Box { + fn into_reflect(self: Box) -> Box { self } - fn as_reflect(&self) -> &dyn Reflect { + fn as_reflect(&self) -> &(dyn Reflect + Send + Sync) { self } - fn as_reflect_mut(&mut self) -> &mut dyn Reflect { + fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + Send + Sync) { self } - fn set(&mut self, value: Box) -> Result<(), Box> { + fn set( + &mut self, + value: Box, + ) -> Result<(), Box> { *self = value.take()?; Ok(()) } @@ -2149,7 +2204,7 @@ impl GetTypeRegistration for &'static str { } impl FromReflect for &'static str { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { reflect.try_downcast_ref::().copied() } } @@ -2164,27 +2219,29 @@ impl PartialReflect for &'static Path { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } @@ -2204,7 +2261,7 @@ impl PartialReflect for &'static Path { ReflectOwned::Opaque(self) } - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { Ok(Box::new(*self)) } @@ -2215,7 +2272,7 @@ impl PartialReflect for &'static Path { Some(hasher.finish()) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { if let Some(value) = value.try_downcast_ref::() { Some(PartialEq::eq(self, value)) } else { @@ -2223,7 +2280,7 @@ impl PartialReflect for &'static Path { } } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { if let Some(value) = value.try_downcast_ref::() { self.clone_from(value); Ok(()) @@ -2250,19 +2307,22 @@ impl Reflect for &'static Path { self } - fn into_reflect(self: Box) -> Box { + fn into_reflect(self: Box) -> Box { self } - fn as_reflect(&self) -> &dyn Reflect { + fn as_reflect(&self) -> &(dyn Reflect + Send + Sync) { self } - fn as_reflect_mut(&mut self) -> &mut dyn Reflect { + fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + Send + Sync) { self } - fn set(&mut self, value: Box) -> Result<(), Box> { + fn set( + &mut self, + value: Box, + ) -> Result<(), Box> { *self = value.take()?; Ok(()) } @@ -2288,7 +2348,7 @@ impl GetTypeRegistration for &'static Path { #[cfg(feature = "std")] impl FromReflect for &'static Path { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { reflect.try_downcast_ref::().copied() } } @@ -2303,27 +2363,29 @@ impl PartialReflect for Cow<'static, Path> { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } @@ -2343,7 +2405,7 @@ impl PartialReflect for Cow<'static, Path> { ReflectOwned::Opaque(self) } - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { Ok(Box::new(self.clone())) } @@ -2354,7 +2416,7 @@ impl PartialReflect for Cow<'static, Path> { Some(hasher.finish()) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { if let Some(value) = value.try_downcast_ref::() { Some(PartialEq::eq(self, value)) } else { @@ -2366,7 +2428,7 @@ impl PartialReflect for Cow<'static, Path> { fmt::Debug::fmt(&self, f) } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { if let Some(value) = value.try_downcast_ref::() { self.clone_from(value); Ok(()) @@ -2393,19 +2455,22 @@ impl Reflect for Cow<'static, Path> { self } - fn into_reflect(self: Box) -> Box { + fn into_reflect(self: Box) -> Box { self } - fn as_reflect(&self) -> &dyn Reflect { + fn as_reflect(&self) -> &(dyn Reflect + Send + Sync) { self } - fn as_reflect_mut(&mut self) -> &mut dyn Reflect { + fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + Send + Sync) { self } - fn set(&mut self, value: Box) -> Result<(), Box> { + fn set( + &mut self, + value: Box, + ) -> Result<(), Box> { *self = value.take()?; Ok(()) } @@ -2425,7 +2490,7 @@ impl_type_path!(::alloc::borrow::Cow<'a: 'static, T: ToOwned + ?Sized>); #[cfg(feature = "std")] impl FromReflect for Cow<'static, Path> { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { Some(reflect.try_downcast_ref::()?.clone()) } } @@ -2461,27 +2526,29 @@ impl PartialReflect for &'static Location<'static> { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } @@ -2501,7 +2568,7 @@ impl PartialReflect for &'static Location<'static> { ReflectOwned::Opaque(self) } - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { Ok(Box::new(*self)) } @@ -2512,7 +2579,7 @@ impl PartialReflect for &'static Location<'static> { Some(hasher.finish()) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { if let Some(value) = value.try_downcast_ref::() { Some(PartialEq::eq(self, value)) } else { @@ -2520,7 +2587,7 @@ impl PartialReflect for &'static Location<'static> { } } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { if let Some(value) = value.try_downcast_ref::() { self.clone_from(value); Ok(()) @@ -2546,19 +2613,22 @@ impl Reflect for &'static Location<'static> { self } - fn into_reflect(self: Box) -> Box { + fn into_reflect(self: Box) -> Box { self } - fn as_reflect(&self) -> &dyn Reflect { + fn as_reflect(&self) -> &(dyn Reflect + Send + Sync) { self } - fn as_reflect_mut(&mut self) -> &mut dyn Reflect { + fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + Send + Sync) { self } - fn set(&mut self, value: Box) -> Result<(), Box> { + fn set( + &mut self, + value: Box, + ) -> Result<(), Box> { *self = value.take()?; Ok(()) } @@ -2581,7 +2651,7 @@ impl GetTypeRegistration for &'static Location<'static> { } impl FromReflect for &'static Location<'static> { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { reflect.try_downcast_ref::().copied() } } @@ -2618,45 +2688,45 @@ mod tests { #[test] fn should_partial_eq_char() { - let a: &dyn PartialReflect = &'x'; - let b: &dyn PartialReflect = &'x'; - let c: &dyn PartialReflect = &'o'; + let a: &(dyn PartialReflect + Send + Sync) = &'x'; + let b: &(dyn PartialReflect + Send + Sync) = &'x'; + let c: &(dyn PartialReflect + Send + Sync) = &'o'; assert!(a.reflect_partial_eq(b).unwrap_or_default()); assert!(!a.reflect_partial_eq(c).unwrap_or_default()); } #[test] fn should_partial_eq_i32() { - let a: &dyn PartialReflect = &123_i32; - let b: &dyn PartialReflect = &123_i32; - let c: &dyn PartialReflect = &321_i32; + let a: &(dyn PartialReflect + Send + Sync) = &123_i32; + let b: &(dyn PartialReflect + Send + Sync) = &123_i32; + let c: &(dyn PartialReflect + Send + Sync) = &321_i32; assert!(a.reflect_partial_eq(b).unwrap_or_default()); assert!(!a.reflect_partial_eq(c).unwrap_or_default()); } #[test] fn should_partial_eq_f32() { - let a: &dyn PartialReflect = &PI; - let b: &dyn PartialReflect = &PI; - let c: &dyn PartialReflect = &TAU; + let a: &(dyn PartialReflect + Send + Sync) = &PI; + let b: &(dyn PartialReflect + Send + Sync) = &PI; + let c: &(dyn PartialReflect + Send + Sync) = &TAU; assert!(a.reflect_partial_eq(b).unwrap_or_default()); assert!(!a.reflect_partial_eq(c).unwrap_or_default()); } #[test] fn should_partial_eq_string() { - let a: &dyn PartialReflect = &String::from("Hello"); - let b: &dyn PartialReflect = &String::from("Hello"); - let c: &dyn PartialReflect = &String::from("World"); + let a: &(dyn PartialReflect + Send + Sync) = &String::from("Hello"); + let b: &(dyn PartialReflect + Send + Sync) = &String::from("Hello"); + let c: &(dyn PartialReflect + Send + Sync) = &String::from("World"); assert!(a.reflect_partial_eq(b).unwrap_or_default()); assert!(!a.reflect_partial_eq(c).unwrap_or_default()); } #[test] fn should_partial_eq_vec() { - let a: &dyn PartialReflect = &vec![1, 2, 3]; - let b: &dyn PartialReflect = &vec![1, 2, 3]; - let c: &dyn PartialReflect = &vec![3, 2, 1]; + let a: &(dyn PartialReflect + Send + Sync) = &vec![1, 2, 3]; + let b: &(dyn PartialReflect + Send + Sync) = &vec![1, 2, 3]; + let c: &(dyn PartialReflect + Send + Sync) = &vec![3, 2, 1]; assert!(a.reflect_partial_eq(b).unwrap_or_default()); assert!(!a.reflect_partial_eq(c).unwrap_or_default()); } @@ -2669,9 +2739,9 @@ mod tests { let mut c = >::default(); c.insert(0usize, 3.21_f64); - let a: &dyn PartialReflect = &a; - let b: &dyn PartialReflect = &b; - let c: &dyn PartialReflect = &c; + let a: &(dyn PartialReflect + Send + Sync) = &a; + let b: &(dyn PartialReflect + Send + Sync) = &b; + let c: &(dyn PartialReflect + Send + Sync) = &c; assert!(a.reflect_partial_eq(b).unwrap_or_default()); assert!(!a.reflect_partial_eq(c).unwrap_or_default()); } @@ -2684,9 +2754,9 @@ mod tests { let mut c = BTreeMap::new(); c.insert(0usize, 3.21_f64); - let a: &dyn Reflect = &a; - let b: &dyn Reflect = &b; - let c: &dyn Reflect = &c; + let a: &(dyn Reflect + Send + Sync) = &a; + let b: &(dyn Reflect + Send + Sync) = &b; + let c: &(dyn Reflect + Send + Sync) = &c; assert!(a .reflect_partial_eq(b.as_partial_reflect()) .unwrap_or_default()); @@ -2697,8 +2767,8 @@ mod tests { #[test] fn should_partial_eq_option() { - let a: &dyn PartialReflect = &Some(123); - let b: &dyn PartialReflect = &Some(123); + let a: &(dyn PartialReflect + Send + Sync) = &Some(123); + let b: &(dyn PartialReflect + Send + Sync) = &Some(123); assert_eq!(Some(true), a.reflect_partial_eq(b)); } @@ -2814,8 +2884,8 @@ mod tests { #[test] fn nonzero_usize_impl_reflect_from_reflect() { - let a: &dyn PartialReflect = &core::num::NonZero::::new(42).unwrap(); - let b: &dyn PartialReflect = &core::num::NonZero::::new(42).unwrap(); + let a: &(dyn PartialReflect + Send + Sync) = &core::num::NonZero::::new(42).unwrap(); + let b: &(dyn PartialReflect + Send + Sync) = &core::num::NonZero::::new(42).unwrap(); assert!(a.reflect_partial_eq(b).unwrap_or_default()); let forty_two: core::num::NonZero = FromReflect::from_reflect(a).unwrap(); assert_eq!(forty_two, core::num::NonZero::::new(42).unwrap()); diff --git a/crates/bevy_reflect/src/kind.rs b/crates/bevy_reflect/src/kind.rs index 3eef10d0e55eb..99f58572ce939 100644 --- a/crates/bevy_reflect/src/kind.rs +++ b/crates/bevy_reflect/src/kind.rs @@ -186,7 +186,7 @@ pub enum ReflectRef<'a> { Enum(&'a dyn Enum), #[cfg(feature = "functions")] Function(&'a dyn Function), - Opaque(&'a dyn PartialReflect), + Opaque(&'a (dyn PartialReflect + Send + Sync)), } impl_reflect_kind_conversions!(ReflectRef<'_>); @@ -199,7 +199,7 @@ impl<'a> ReflectRef<'a> { impl_cast_method!(as_map: Map => &'a dyn Map); impl_cast_method!(as_set: Set => &'a dyn Set); impl_cast_method!(as_enum: Enum => &'a dyn Enum); - impl_cast_method!(as_opaque: Opaque => &'a dyn PartialReflect); + impl_cast_method!(as_opaque: Opaque => &'a (dyn PartialReflect + Send + Sync)); } /// A mutable enumeration of ["kinds"] of a reflected type. @@ -221,7 +221,7 @@ pub enum ReflectMut<'a> { Enum(&'a mut dyn Enum), #[cfg(feature = "functions")] Function(&'a mut dyn Function), - Opaque(&'a mut dyn PartialReflect), + Opaque(&'a mut (dyn PartialReflect + Send + Sync)), } impl_reflect_kind_conversions!(ReflectMut<'_>); @@ -234,7 +234,7 @@ impl<'a> ReflectMut<'a> { impl_cast_method!(as_map: Map => &'a mut dyn Map); impl_cast_method!(as_set: Set => &'a mut dyn Set); impl_cast_method!(as_enum: Enum => &'a mut dyn Enum); - impl_cast_method!(as_opaque: Opaque => &'a mut dyn PartialReflect); + impl_cast_method!(as_opaque: Opaque => &'a mut (dyn PartialReflect + Send + Sync)); } /// An owned enumeration of ["kinds"] of a reflected type. @@ -256,7 +256,7 @@ pub enum ReflectOwned { Enum(Box), #[cfg(feature = "functions")] Function(Box), - Opaque(Box), + Opaque(Box), } impl_reflect_kind_conversions!(ReflectOwned); @@ -269,7 +269,7 @@ impl ReflectOwned { impl_cast_method!(into_map: Map => Box); impl_cast_method!(into_set: Set => Box); impl_cast_method!(into_enum: Enum => Box); - impl_cast_method!(into_value: Opaque => Box); + impl_cast_method!(into_value: Opaque => Box); } #[cfg(test)] diff --git a/crates/bevy_reflect/src/lib.rs b/crates/bevy_reflect/src/lib.rs index 31540a54d2e9b..7f0f5d0cf5b33 100644 --- a/crates/bevy_reflect/src/lib.rs +++ b/crates/bevy_reflect/src/lib.rs @@ -41,9 +41,9 @@ //! //! Its primary purpose is to allow all implementors to be passed around //! as a `dyn PartialReflect` trait object in one of the following forms: -//! * `&dyn PartialReflect` -//! * `&mut dyn PartialReflect` -//! * `Box` +//! * `&(dyn PartialReflect + Send + Sync)` +//! * `&mut (dyn PartialReflect + Send + Sync)` +//! * `Box` //! //! This allows values of types implementing `PartialReflect` //! to be operated upon completely dynamically (at a small [runtime cost]). @@ -70,15 +70,15 @@ //! Since `T: Reflect` implies `T: PartialReflect`, conversion from a `dyn Reflect` to a `dyn PartialReflect` //! trait object (upcasting) is infallible and can be performed with one of the following methods. //! Note that these are temporary while [the language feature for dyn upcasting coercion] is experimental: -//! * [`PartialReflect::as_partial_reflect`] for `&dyn PartialReflect` -//! * [`PartialReflect::as_partial_reflect_mut`] for `&mut dyn PartialReflect` -//! * [`PartialReflect::into_partial_reflect`] for `Box` +//! * [`PartialReflect::as_partial_reflect`] for `&(dyn PartialReflect + Send + Sync)` +//! * [`PartialReflect::as_partial_reflect_mut`] for `&mut (dyn PartialReflect + Send + Sync)` +//! * [`PartialReflect::into_partial_reflect`] for `Box` //! //! For conversion in the other direction — downcasting `dyn PartialReflect` to `dyn Reflect` — //! there are fallible methods: -//! * [`PartialReflect::try_as_reflect`] for `&dyn Reflect` -//! * [`PartialReflect::try_as_reflect_mut`] for `&mut dyn Reflect` -//! * [`PartialReflect::try_into_reflect`] for `Box` +//! * [`PartialReflect::try_as_reflect`] for `&(dyn Reflect + Send + Sync)` +//! * [`PartialReflect::try_as_reflect_mut`] for `&mut (dyn Reflect + Send + Sync)` +//! * [`PartialReflect::try_into_reflect`] for `Box` //! //! Additionally, [`FromReflect::from_reflect`] can be used to convert a `dyn PartialReflect` to a concrete type //! which implements `Reflect`. @@ -144,7 +144,7 @@ //! let my_struct: Box = Box::new(MyStruct { //! foo: 123 //! }); -//! let foo: &dyn PartialReflect = my_struct.field("foo").unwrap(); +//! let foo: &(dyn PartialReflect + Send + Sync) = my_struct.field("foo").unwrap(); //! assert_eq!(Some(&123), foo.try_downcast_ref::()); //! ``` //! @@ -159,7 +159,7 @@ //! //! ``` //! # use bevy_reflect::{PartialReflect, ReflectRef}; -//! let my_tuple: Box = Box::new((1, 2, 3)); +//! let my_tuple: Box = Box::new((1, 2, 3)); //! let my_tuple = my_tuple.reflect_ref().as_tuple().unwrap(); //! assert_eq!(3, my_tuple.field_len()); //! ``` @@ -215,12 +215,12 @@ //! # struct MyStruct { //! # foo: i32 //! # } -//! let original: Box = Box::new(MyStruct { +//! let original: Box = Box::new(MyStruct { //! foo: 123 //! }); //! //! // `dynamic` will be a `DynamicStruct` representing a `MyStruct` -//! let dynamic: Box = original.to_dynamic(); +//! let dynamic: Box = original.to_dynamic(); //! assert!(dynamic.represents::()); //! ``` //! @@ -249,11 +249,11 @@ //! # struct MyStruct { //! # foo: i32 //! # } -//! let original: Box = Box::new(MyStruct { +//! let original: Box = Box::new(MyStruct { //! foo: 123 //! }); //! -//! let dynamic: Box = original.to_dynamic(); +//! let dynamic: Box = original.to_dynamic(); //! let value = dynamic.try_take::().unwrap(); // PANIC! //! ``` //! @@ -274,11 +274,11 @@ //! struct MyStruct { //! foo: i32 //! } -//! let original: Box = Box::new(MyStruct { +//! let original: Box = Box::new(MyStruct { //! foo: 123 //! }); //! -//! let dynamic: Box = original.to_dynamic(); +//! let dynamic: Box = original.to_dynamic(); //! let value = ::from_reflect(&*dynamic).unwrap(); // OK! //! ``` //! @@ -340,7 +340,7 @@ //! let registration = registry.get(core::any::TypeId::of::()).unwrap(); //! let reflect_default = registration.data::().unwrap(); //! -//! let new_value: Box = reflect_default.default(); +//! let new_value: Box = reflect_default.default(); //! assert!(new_value.is::()); //! ``` //! @@ -371,7 +371,7 @@ //! # use bevy_reflect::{Reflect, reflect_trait, TypeRegistry}; //! #[reflect_trait] // Generates a `ReflectMyTrait` type //! pub trait MyTrait {} -//! impl MyTrait for T {} +//! impl MyTrait for T {} //! //! let mut registry = TypeRegistry::new(); //! registry.register_type_data::(); @@ -403,7 +403,7 @@ //! and the value is the serialized data. //! The `TypedReflectSerializer` will simply output the serialized data. //! -//! The `ReflectDeserializer` can be used to deserialize this map and return a `Box`, +//! The `ReflectDeserializer` can be used to deserialize this map and return a `Box`, //! where the underlying type will be a dynamic type representing some concrete type (except for opaque types). //! //! Again, it's important to remember that dynamic types may need to be converted to their concrete counterparts @@ -435,7 +435,7 @@ //! //! // Deserialize //! let reflect_deserializer = ReflectDeserializer::new(®istry); -//! let deserialized_value: Box = reflect_deserializer.deserialize( +//! let deserialized_value: Box = reflect_deserializer.deserialize( //! &mut ron::Deserializer::from_str(&serialized_value).unwrap() //! ).unwrap(); //! @@ -1824,7 +1824,7 @@ mod tests { w: Cow::Owned(vec![1, 2, 3]), }; - let foo2: Box = Box::new(foo.clone()); + let foo2: Box = Box::new(foo.clone()); assert_eq!(foo, *foo2.downcast::().unwrap()); } @@ -1861,7 +1861,7 @@ mod tests { x: u32, } - let x: Box = Box::new(Bar { x: 2 }); + let x: Box = Box::new(Bar { x: 2 }); let y = x.take::().unwrap(); assert_eq!(y, Bar { x: 2 }); } @@ -2014,12 +2014,12 @@ mod tests { // TypeInfo (unsized) assert_eq!( - TypeId::of::(), - ::type_info().type_id() + TypeId::of::(), + <(dyn Reflect + Send + Sync) as Typed>::type_info().type_id() ); // TypeInfo (instance) - let value: &dyn Reflect = &123_i32; + let value: &(dyn Reflect + Send + Sync) = &123_i32; let info = value.reflect_type_info(); assert!(info.is::()); @@ -2040,7 +2040,7 @@ mod tests { assert_eq!("foo", info.field("foo").unwrap().name()); assert_eq!(usize::type_path(), info.field_at(1).unwrap().type_path()); - let value: &dyn Reflect = &MyStruct { foo: 123, bar: 321 }; + let value: &(dyn Reflect + Send + Sync) = &MyStruct { foo: 123, bar: 321 }; let info = value.reflect_type_info(); assert!(info.is::()); @@ -2059,7 +2059,7 @@ mod tests { assert!(info.field("foo").unwrap().type_info().unwrap().is::()); assert_eq!(usize::type_path(), info.field_at(1).unwrap().type_path()); - let value: &dyn Reflect = &MyGenericStruct { + let value: &(dyn Reflect + Send + Sync) = &MyGenericStruct { foo: String::from("Hello!"), bar: 321, }; @@ -2089,7 +2089,7 @@ mod tests { panic!("Expected `TypeInfo::Struct`"); } - let value: &dyn Reflect = &MyDynamicStruct { + let value: &(dyn Reflect + Send + Sync) = &MyDynamicStruct { foo: DynamicStruct::default(), bar: 321, }; @@ -2118,7 +2118,7 @@ mod tests { assert_eq!(f32::type_path(), info.field_at(1).unwrap().type_path()); assert!(info.field_at(1).unwrap().type_info().unwrap().is::()); - let value: &dyn Reflect = &(123_u32, 1.23_f32, String::from("Hello!")); + let value: &(dyn Reflect + Send + Sync) = &(123_u32, 1.23_f32, String::from("Hello!")); let info = value.reflect_type_info(); assert!(info.is::()); @@ -2133,7 +2133,7 @@ mod tests { assert_eq!(MyList::type_path(), info.type_path()); assert_eq!(usize::type_path(), info.item_ty().path()); - let value: &dyn Reflect = &vec![123_usize]; + let value: &(dyn Reflect + Send + Sync) = &vec![123_usize]; let info = value.reflect_type_info(); assert!(info.is::()); @@ -2150,7 +2150,7 @@ mod tests { assert_eq!(String::type_path(), info.item_ty().path()); let value: MySmallVec = smallvec::smallvec![String::default(); 2]; - let value: &dyn Reflect = &value; + let value: &(dyn Reflect + Send + Sync) = &value; let info = value.reflect_type_info(); assert!(info.is::()); } @@ -2166,7 +2166,7 @@ mod tests { assert_eq!(usize::type_path(), info.item_ty().path()); assert_eq!(3, info.capacity()); - let value: &dyn Reflect = &[1usize, 2usize, 3usize]; + let value: &(dyn Reflect + Send + Sync) = &[1usize, 2usize, 3usize]; let info = value.reflect_type_info(); assert!(info.is::()); @@ -2178,7 +2178,7 @@ mod tests { assert!(info.is::()); assert_eq!(core::any::type_name::(), info.type_path()); - let value: &dyn Reflect = &Cow::<'static, str>::Owned("Hello!".to_string()); + let value: &(dyn Reflect + Send + Sync) = &Cow::<'static, str>::Owned("Hello!".to_string()); let info = value.reflect_type_info(); assert!(info.is::()); @@ -2193,7 +2193,7 @@ mod tests { assert_eq!(core::any::type_name::(), info.type_path()); assert_eq!(core::any::type_name::(), info.item_ty().path()); - let value: &dyn Reflect = &Cow::<'static, [u8]>::Owned(vec![0, 1, 2, 3]); + let value: &(dyn Reflect + Send + Sync) = &Cow::<'static, [u8]>::Owned(vec![0, 1, 2, 3]); let info = value.reflect_type_info(); assert!(info.is::()); @@ -2211,7 +2211,7 @@ mod tests { assert_eq!(usize::type_path(), info.key_ty().path()); assert_eq!(f32::type_path(), info.value_ty().path()); - let value: &dyn Reflect = &MyMap::default(); + let value: &(dyn Reflect + Send + Sync) = &MyMap::default(); let info = value.reflect_type_info(); assert!(info.is::()); @@ -2223,7 +2223,7 @@ mod tests { assert!(info.is::()); assert_eq!(MyValue::type_path(), info.type_path()); - let value: &dyn Reflect = &String::from("Hello!"); + let value: &(dyn Reflect + Send + Sync) = &String::from("Hello!"); let info = value.reflect_type_info(); assert!(info.is::()); } @@ -2461,7 +2461,7 @@ mod tests { impl TestTrait for TestStruct {} - let trait_object: Box = Box::new(TestStruct); + let trait_object: Box = Box::new(TestStruct); // Should compile: let _ = trait_object.as_reflect(); @@ -2529,7 +2529,7 @@ mod tests { ignored: 321, }; - let reflected: &dyn Reflect = &test; + let reflected: &(dyn Reflect + Send + Sync) = &test; let expected = r#" bevy_reflect::tests::Test { value: 123, @@ -2579,7 +2579,7 @@ bevy_reflect::tests::Test { } let foo = Foo(123); - let foo: &dyn PartialReflect = &foo; + let foo: &(dyn PartialReflect + Send + Sync) = &foo; assert!(foo.reflect_hash().is_some()); assert_eq!(Some(true), foo.reflect_partial_eq(foo)); @@ -2599,7 +2599,7 @@ bevy_reflect::tests::Test { } let foo = Foo { a: 1 }; - let foo: &dyn Reflect = &foo; + let foo: &(dyn Reflect + Send + Sync) = &foo; assert_eq!("123", format!("{:?}", foo)); } @@ -2758,14 +2758,14 @@ bevy_reflect::tests::Test { fn can_opt_out_type_path() { #[derive(Reflect)] #[reflect(type_path = false)] - struct Foo { + struct Foo { #[reflect(ignore)] _marker: PhantomData, } struct NotTypePath; - impl TypePath for Foo { + impl TypePath for Foo { fn type_path() -> &'static str { core::any::type_name::() } @@ -3171,7 +3171,7 @@ bevy_reflect::tests::Test { } #[reflect_remote(external_crate::TheirOuter)] - struct MyOuter { + struct MyOuter { #[reflect(remote = MyInner)] pub a: external_crate::TheirInner, #[reflect(remote = MyInner)] @@ -3219,7 +3219,7 @@ bevy_reflect::tests::Test { #[reflect_remote(external_crate::TheirOuter)] #[derive(Debug)] - enum MyOuter { + enum MyOuter { Unit, Tuple(#[reflect(remote = MyInner)] external_crate::TheirInner), Struct { @@ -3230,7 +3230,7 @@ bevy_reflect::tests::Test { #[reflect_remote(external_crate::TheirInner)] #[derive(Debug)] - enum MyInner { + enum MyInner { Unit, Tuple(T), Struct { value: T }, @@ -3275,7 +3275,7 @@ bevy_reflect::tests::Test { pub value: String, } - let input: Box = Box::new(MyType(external_crate::TheirType { + let input: Box = Box::new(MyType(external_crate::TheirType { value: "Hello".to_string(), })); @@ -3309,9 +3309,10 @@ bevy_reflect::tests::Test { pub value: String, } - let input: Box = Box::new(MyType(external_crate::TheirType { - value: "Hello".to_string(), - })); + let input: Box = + Box::new(MyType(external_crate::TheirType { + value: "Hello".to_string(), + })); let output: external_crate::TheirType = input .try_take() @@ -3336,7 +3337,7 @@ bevy_reflect::tests::Test { } #[reflect_remote(external_crate::TheirOuter)] - struct MyOuter { + struct MyOuter { #[reflect(remote = MyInner)] pub inner: external_crate::TheirInner, } @@ -3344,7 +3345,7 @@ bevy_reflect::tests::Test { #[reflect_remote(external_crate::TheirInner)] struct MyInner(pub T); - let input: Box = Box::new(MyOuter(external_crate::TheirOuter { + let input: Box = Box::new(MyOuter(external_crate::TheirOuter { inner: external_crate::TheirInner(123), })); diff --git a/crates/bevy_reflect/src/list.rs b/crates/bevy_reflect/src/list.rs index 2e1c08567601b..4066c68427c07 100644 --- a/crates/bevy_reflect/src/list.rs +++ b/crates/bevy_reflect/src/list.rs @@ -44,7 +44,7 @@ use crate::{ /// let foo: &mut dyn List = &mut vec![123_u32, 456_u32, 789_u32]; /// assert_eq!(foo.len(), 3); /// -/// let last_field: Box = foo.pop().unwrap(); +/// let last_field: Box = foo.pop().unwrap(); /// assert_eq!(last_field.try_downcast_ref::(), Some(&789)); /// ``` /// @@ -53,32 +53,32 @@ use crate::{ /// [type-erasing]: https://doc.rust-lang.org/book/ch17-02-trait-objects.html pub trait List: PartialReflect { /// Returns a reference to the element at `index`, or `None` if out of bounds. - fn get(&self, index: usize) -> Option<&dyn PartialReflect>; + fn get(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)>; /// Returns a mutable reference to the element at `index`, or `None` if out of bounds. - fn get_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>; + fn get_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)>; /// Inserts an element at position `index` within the list, /// shifting all elements after it towards the back of the list. /// /// # Panics /// Panics if `index > len`. - fn insert(&mut self, index: usize, element: Box); + fn insert(&mut self, index: usize, element: Box); /// Removes and returns the element at position `index` within the list, /// shifting all elements before it towards the front of the list. /// /// # Panics /// Panics if `index` is out of bounds. - fn remove(&mut self, index: usize) -> Box; + fn remove(&mut self, index: usize) -> Box; /// Appends an element to the _back_ of the list. - fn push(&mut self, value: Box) { + fn push(&mut self, value: Box) { self.insert(self.len(), value); } /// Removes the _back_ element from the list and returns it, or [`None`] if it is empty. - fn pop(&mut self) -> Option> { + fn pop(&mut self) -> Option> { if self.is_empty() { None } else { @@ -101,7 +101,7 @@ pub trait List: PartialReflect { /// /// After calling this function, `self` will be empty. The order of items in the returned /// [`Vec`] will match the order of items in `self`. - fn drain(&mut self) -> Vec>; + fn drain(&mut self) -> Vec>; /// Clones the list, producing a [`DynamicList`]. #[deprecated(since = "0.16.0", note = "use `to_dynamic_list` instead")] @@ -136,7 +136,8 @@ pub struct ListInfo { impl ListInfo { /// Create a new [`ListInfo`]. - pub fn new() -> Self { + pub fn new( + ) -> Self { Self { ty: Type::of::(), generics: Generics::new(), @@ -183,7 +184,7 @@ impl ListInfo { #[derive(Default)] pub struct DynamicList { represented_type: Option<&'static TypeInfo>, - values: Vec>, + values: Vec>, } impl DynamicList { @@ -206,38 +207,38 @@ impl DynamicList { } /// Appends a typed value to the list. - pub fn push(&mut self, value: T) { + pub fn push(&mut self, value: T) { self.values.push(Box::new(value)); } /// Appends a [`Reflect`] trait object to the list. - pub fn push_box(&mut self, value: Box) { + pub fn push_box(&mut self, value: Box) { self.values.push(value); } } impl List for DynamicList { - fn get(&self, index: usize) -> Option<&dyn PartialReflect> { + fn get(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)> { self.values.get(index).map(|value| &**value) } - fn get_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect> { + fn get_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)> { self.values.get_mut(index).map(|value| &mut **value) } - fn insert(&mut self, index: usize, element: Box) { + fn insert(&mut self, index: usize, element: Box) { self.values.insert(index, element); } - fn remove(&mut self, index: usize) -> Box { + fn remove(&mut self, index: usize) -> Box { self.values.remove(index) } - fn push(&mut self, value: Box) { + fn push(&mut self, value: Box) { DynamicList::push_box(self, value); } - fn pop(&mut self) -> Option> { + fn pop(&mut self) -> Option> { self.values.pop() } @@ -249,7 +250,7 @@ impl List for DynamicList { ListIter::new(self) } - fn drain(&mut self) -> Vec> { + fn drain(&mut self) -> Vec> { self.values.drain(..).collect() } } @@ -261,37 +262,39 @@ impl PartialReflect for DynamicList { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } #[inline] - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } #[inline] - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Err(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { None } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { None } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { list_apply(self, value); } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { list_try_apply(self, value) } @@ -320,7 +323,7 @@ impl PartialReflect for DynamicList { list_hash(self) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { list_partial_eq(self, value) } @@ -344,8 +347,8 @@ impl Debug for DynamicList { } } -impl FromIterator> for DynamicList { - fn from_iter>>(values: I) -> Self { +impl FromIterator> for DynamicList { + fn from_iter>>(values: I) -> Self { Self { represented_type: None, values: values.into_iter().collect(), @@ -353,7 +356,7 @@ impl FromIterator> for DynamicList { } } -impl FromIterator for DynamicList { +impl FromIterator for DynamicList { fn from_iter>(values: I) -> Self { values .into_iter() @@ -363,7 +366,7 @@ impl FromIterator for DynamicList { } impl IntoIterator for DynamicList { - type Item = Box; + type Item = Box; type IntoIter = alloc::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { @@ -372,7 +375,7 @@ impl IntoIterator for DynamicList { } impl<'a> IntoIterator for &'a DynamicList { - type Item = &'a dyn PartialReflect; + type Item = &'a (dyn PartialReflect + Send + Sync); type IntoIter = ListIter<'a>; fn into_iter(self) -> Self::IntoIter { @@ -395,7 +398,7 @@ impl ListIter<'_> { } impl<'a> Iterator for ListIter<'a> { - type Item = &'a dyn PartialReflect; + type Item = &'a (dyn PartialReflect + Send + Sync); #[inline] fn next(&mut self) -> Option { @@ -434,7 +437,7 @@ pub fn list_hash(list: &L) -> Option { /// /// This function panics if `b` is not a list. #[inline] -pub fn list_apply(a: &mut L, b: &dyn PartialReflect) { +pub fn list_apply(a: &mut L, b: &(dyn PartialReflect + Send + Sync)) { if let Err(err) = list_try_apply(a, b) { panic!("{err}"); } @@ -451,7 +454,10 @@ pub fn list_apply(a: &mut L, b: &dyn PartialReflect) { /// This function returns an [`ApplyError::MismatchedKinds`] if `b` is not a list or if /// applying elements to each other fails. #[inline] -pub fn list_try_apply(a: &mut L, b: &dyn PartialReflect) -> Result<(), ApplyError> { +pub fn list_try_apply( + a: &mut L, + b: &(dyn PartialReflect + Send + Sync), +) -> Result<(), ApplyError> { let list_value = b.reflect_ref().as_list()?; for (i, value) in list_value.iter().enumerate() { @@ -476,7 +482,10 @@ pub fn list_try_apply(a: &mut L, b: &dyn PartialReflect) -> Result<(), /// /// Returns [`None`] if the comparison couldn't even be performed. #[inline] -pub fn list_partial_eq(a: &L, b: &dyn PartialReflect) -> Option { +pub fn list_partial_eq( + a: &L, + b: &(dyn PartialReflect + Send + Sync), +) -> Option { let ReflectRef::List(list) = b.reflect_ref() else { return Some(false); }; @@ -501,7 +510,7 @@ pub fn list_partial_eq(a: &L, b: &dyn PartialReflect) -> Optio /// ``` /// use bevy_reflect::Reflect; /// -/// let my_list: &dyn Reflect = &vec![1, 2, 3]; +/// let my_list: &(dyn Reflect + Send + Sync) = &vec![1, 2, 3]; /// println!("{:#?}", my_list); /// /// // Output: diff --git a/crates/bevy_reflect/src/map.rs b/crates/bevy_reflect/src/map.rs index 0b18132fba7dc..e4bff574aa4eb 100644 --- a/crates/bevy_reflect/src/map.rs +++ b/crates/bevy_reflect/src/map.rs @@ -37,7 +37,7 @@ use alloc::{boxed::Box, format, vec::Vec}; /// foo.insert_boxed(Box::new(123_u32), Box::new(true)); /// assert_eq!(foo.len(), 1); /// -/// let field: &dyn PartialReflect = foo.get(&123_u32).unwrap(); +/// let field: &(dyn PartialReflect + Send + Sync) = foo.get(&123_u32).unwrap(); /// assert_eq!(field.try_downcast_ref::(), Some(&true)); /// ``` /// @@ -49,21 +49,36 @@ pub trait Map: PartialReflect { /// Returns a reference to the value associated with the given key. /// /// If no value is associated with `key`, returns `None`. - fn get(&self, key: &dyn PartialReflect) -> Option<&dyn PartialReflect>; + fn get( + &self, + key: &(dyn PartialReflect + Send + Sync), + ) -> Option<&(dyn PartialReflect + Send + Sync)>; /// Returns a mutable reference to the value associated with the given key. /// /// If no value is associated with `key`, returns `None`. - fn get_mut(&mut self, key: &dyn PartialReflect) -> Option<&mut dyn PartialReflect>; + fn get_mut( + &mut self, + key: &(dyn PartialReflect + Send + Sync), + ) -> Option<&mut (dyn PartialReflect + Send + Sync)>; /// Returns the key-value pair at `index` by reference, or `None` if out of bounds. - fn get_at(&self, index: usize) -> Option<(&dyn PartialReflect, &dyn PartialReflect)>; + fn get_at( + &self, + index: usize, + ) -> Option<( + &(dyn PartialReflect + Send + Sync), + &(dyn PartialReflect + Send + Sync), + )>; /// Returns the key-value pair at `index` by reference where the value is a mutable reference, or `None` if out of bounds. fn get_at_mut( &mut self, index: usize, - ) -> Option<(&dyn PartialReflect, &mut dyn PartialReflect)>; + ) -> Option<( + &(dyn PartialReflect + Send + Sync), + &mut (dyn PartialReflect + Send + Sync), + )>; /// Returns the number of elements in the map. fn len(&self) -> usize; @@ -79,7 +94,12 @@ pub trait Map: PartialReflect { /// Drain the key-value pairs of this map to get a vector of owned values. /// /// After calling this function, `self` will be empty. - fn drain(&mut self) -> Vec<(Box, Box)>; + fn drain( + &mut self, + ) -> Vec<( + Box, + Box, + )>; /// Clones the map, producing a [`DynamicMap`]. #[deprecated(since = "0.16.0", note = "use `to_dynamic_map` instead")] @@ -103,15 +123,18 @@ pub trait Map: PartialReflect { /// If the map did have this key present, the value is updated, and the old value is returned. fn insert_boxed( &mut self, - key: Box, - value: Box, - ) -> Option>; + key: Box, + value: Box, + ) -> Option>; /// Removes an entry from the map. /// /// If the map did not have this key present, `None` is returned. /// If the map did have this key present, the removed value is returned. - fn remove(&mut self, key: &dyn PartialReflect) -> Option>; + fn remove( + &mut self, + key: &(dyn PartialReflect + Send + Sync), + ) -> Option>; /// Will return `None` if [`TypeInfo`] is not available. fn get_represented_map_info(&self) -> Option<&'static MapInfo> { @@ -136,8 +159,8 @@ impl MapInfo { /// Create a new [`MapInfo`]. pub fn new< TMap: Map + TypePath, - TKey: Reflect + MaybeTyped + TypePath, - TValue: Reflect + MaybeTyped + TypePath, + TKey: Reflect + Send + Sync + MaybeTyped + TypePath, + TValue: Reflect + Send + Sync + MaybeTyped + TypePath, >() -> Self { Self { ty: Type::of::(), @@ -226,7 +249,10 @@ macro_rules! hash_error { #[derive(Default)] pub struct DynamicMap { represented_type: Option<&'static TypeInfo>, - values: Vec<(Box, Box)>, + values: Vec<( + Box, + Box, + )>, indices: HashTable, } @@ -251,17 +277,24 @@ impl DynamicMap { } /// Inserts a typed key-value pair into the map. - pub fn insert(&mut self, key: K, value: V) { + pub fn insert( + &mut self, + key: K, + value: V, + ) { self.insert_boxed(Box::new(key), Box::new(value)); } - fn internal_hash(value: &dyn PartialReflect) -> u64 { + fn internal_hash(value: &(dyn PartialReflect + Send + Sync)) -> u64 { value.reflect_hash().expect(&hash_error!(value)) } fn internal_eq<'a>( - value: &'a dyn PartialReflect, - values: &'a [(Box, Box)], + value: &'a (dyn PartialReflect + Send + Sync), + values: &'a [( + Box, + Box, + )], ) -> impl FnMut(&usize) -> bool + 'a { |&index| { value @@ -272,7 +305,10 @@ impl DynamicMap { } impl Map for DynamicMap { - fn get(&self, key: &dyn PartialReflect) -> Option<&dyn PartialReflect> { + fn get( + &self, + key: &(dyn PartialReflect + Send + Sync), + ) -> Option<&(dyn PartialReflect + Send + Sync)> { let hash = Self::internal_hash(key); let eq = Self::internal_eq(key, &self.values); self.indices @@ -280,7 +316,10 @@ impl Map for DynamicMap { .map(|&index| &*self.values[index].1) } - fn get_mut(&mut self, key: &dyn PartialReflect) -> Option<&mut dyn PartialReflect> { + fn get_mut( + &mut self, + key: &(dyn PartialReflect + Send + Sync), + ) -> Option<&mut (dyn PartialReflect + Send + Sync)> { let hash = Self::internal_hash(key); let eq = Self::internal_eq(key, &self.values); self.indices @@ -288,7 +327,13 @@ impl Map for DynamicMap { .map(|&index| &mut *self.values[index].1) } - fn get_at(&self, index: usize) -> Option<(&dyn PartialReflect, &dyn PartialReflect)> { + fn get_at( + &self, + index: usize, + ) -> Option<( + &(dyn PartialReflect + Send + Sync), + &(dyn PartialReflect + Send + Sync), + )> { self.values .get(index) .map(|(key, value)| (&**key, &**value)) @@ -297,7 +342,10 @@ impl Map for DynamicMap { fn get_at_mut( &mut self, index: usize, - ) -> Option<(&dyn PartialReflect, &mut dyn PartialReflect)> { + ) -> Option<( + &(dyn PartialReflect + Send + Sync), + &mut (dyn PartialReflect + Send + Sync), + )> { self.values .get_mut(index) .map(|(key, value)| (&**key, &mut **value)) @@ -311,15 +359,20 @@ impl Map for DynamicMap { MapIter::new(self) } - fn drain(&mut self) -> Vec<(Box, Box)> { + fn drain( + &mut self, + ) -> Vec<( + Box, + Box, + )> { self.values.drain(..).collect() } fn insert_boxed( &mut self, - key: Box, - value: Box, - ) -> Option> { + key: Box, + value: Box, + ) -> Option> { assert_eq!( key.reflect_partial_eq(&*key), Some(true), @@ -346,7 +399,10 @@ impl Map for DynamicMap { } } - fn remove(&mut self, key: &dyn PartialReflect) -> Option> { + fn remove( + &mut self, + key: &(dyn PartialReflect + Send + Sync), + ) -> Option> { let hash = Self::internal_hash(key); let eq = Self::internal_eq(key, &self.values); match self.indices.find_entry(hash, eq) { @@ -382,37 +438,39 @@ impl PartialReflect for DynamicMap { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } #[inline] - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } #[inline] - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Err(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { None } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { None } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { map_apply(self, value); } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { map_try_apply(self, value) } @@ -432,7 +490,7 @@ impl PartialReflect for DynamicMap { ReflectOwned::Map(self) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { map_partial_eq(self, value) } @@ -471,7 +529,10 @@ impl MapIter<'_> { } impl<'a> Iterator for MapIter<'a> { - type Item = (&'a dyn PartialReflect, &'a dyn PartialReflect); + type Item = ( + &'a (dyn PartialReflect + Send + Sync), + &'a (dyn PartialReflect + Send + Sync), + ); fn next(&mut self) -> Option { let value = self.map.get_at(self.index); @@ -485,8 +546,20 @@ impl<'a> Iterator for MapIter<'a> { } } -impl FromIterator<(Box, Box)> for DynamicMap { - fn from_iter, Box)>>( +impl + FromIterator<( + Box, + Box, + )> for DynamicMap +{ + fn from_iter< + I: IntoIterator< + Item = ( + Box, + Box, + ), + >, + >( items: I, ) -> Self { let mut map = Self::default(); @@ -497,7 +570,9 @@ impl FromIterator<(Box, Box)> for Dynami } } -impl FromIterator<(K, V)> for DynamicMap { +impl + FromIterator<(K, V)> for DynamicMap +{ fn from_iter>(items: I) -> Self { let mut map = Self::default(); for (key, value) in items.into_iter() { @@ -508,7 +583,10 @@ impl FromIterator<(K, V)> for DynamicMap { } impl IntoIterator for DynamicMap { - type Item = (Box, Box); + type Item = ( + Box, + Box, + ); type IntoIter = alloc::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { @@ -517,7 +595,10 @@ impl IntoIterator for DynamicMap { } impl<'a> IntoIterator for &'a DynamicMap { - type Item = (&'a dyn PartialReflect, &'a dyn PartialReflect); + type Item = ( + &'a (dyn PartialReflect + Send + Sync), + &'a (dyn PartialReflect + Send + Sync), + ); type IntoIter = MapIter<'a>; fn into_iter(self) -> Self::IntoIter { @@ -537,7 +618,10 @@ impl<'a> ExactSizeIterator for MapIter<'a> {} /// /// Returns [`None`] if the comparison couldn't even be performed. #[inline] -pub fn map_partial_eq(a: &M, b: &dyn PartialReflect) -> Option { +pub fn map_partial_eq( + a: &M, + b: &(dyn PartialReflect + Send + Sync), +) -> Option { let ReflectRef::Map(map) = b.reflect_ref() else { return Some(false); }; @@ -569,7 +653,7 @@ pub fn map_partial_eq(a: &M, b: &dyn PartialReflect) -> Option< /// /// let mut my_map = HashMap::new(); /// my_map.insert(123, String::from("Hello")); -/// println!("{:#?}", &my_map as &dyn Reflect); +/// println!("{:#?}", &my_map as &(dyn Reflect + Send + Sync)); /// /// // Output: /// @@ -594,7 +678,7 @@ pub fn map_debug(dyn_map: &dyn Map, f: &mut Formatter<'_>) -> core::fmt::Result /// /// This function panics if `b` is not a reflected map. #[inline] -pub fn map_apply(a: &mut M, b: &dyn PartialReflect) { +pub fn map_apply(a: &mut M, b: &(dyn PartialReflect + Send + Sync)) { if let Err(err) = map_try_apply(a, b) { panic!("{err}"); } @@ -610,7 +694,10 @@ pub fn map_apply(a: &mut M, b: &dyn PartialReflect) { /// This function returns an [`ApplyError::MismatchedKinds`] if `b` is not a reflected map or if /// applying elements to each other fails. #[inline] -pub fn map_try_apply(a: &mut M, b: &dyn PartialReflect) -> Result<(), ApplyError> { +pub fn map_try_apply( + a: &mut M, + b: &(dyn PartialReflect + Send + Sync), +) -> Result<(), ApplyError> { let map_value = b.reflect_ref().as_map()?; for (key, b_value) in map_value.iter() { diff --git a/crates/bevy_reflect/src/path/access.rs b/crates/bevy_reflect/src/path/access.rs index c0a141fcbaee1..d82647702a6a5 100644 --- a/crates/bevy_reflect/src/path/access.rs +++ b/crates/bevy_reflect/src/path/access.rs @@ -52,9 +52,9 @@ impl<'a> Access<'a> { pub(super) fn element<'r>( &self, - base: &'r dyn PartialReflect, + base: &'r (dyn PartialReflect + Send + Sync), offset: Option, - ) -> Result<&'r dyn PartialReflect, AccessError<'a>> { + ) -> Result<&'r (dyn PartialReflect + Send + Sync), AccessError<'a>> { self.element_inner(base) .and_then(|opt| opt.ok_or(AccessErrorKind::MissingField(base.reflect_kind()))) .map_err(|err| err.with_access(self.clone(), offset)) @@ -62,8 +62,8 @@ impl<'a> Access<'a> { fn element_inner<'r>( &self, - base: &'r dyn PartialReflect, - ) -> InnerResult> { + base: &'r (dyn PartialReflect + Send + Sync), + ) -> InnerResult> { use ReflectRef::*; let invalid_variant = @@ -109,9 +109,9 @@ impl<'a> Access<'a> { pub(super) fn element_mut<'r>( &self, - base: &'r mut dyn PartialReflect, + base: &'r mut (dyn PartialReflect + Send + Sync), offset: Option, - ) -> Result<&'r mut dyn PartialReflect, AccessError<'a>> { + ) -> Result<&'r mut (dyn PartialReflect + Send + Sync), AccessError<'a>> { let kind = base.reflect_kind(); self.element_inner_mut(base) @@ -121,8 +121,8 @@ impl<'a> Access<'a> { fn element_inner_mut<'r>( &self, - base: &'r mut dyn PartialReflect, - ) -> InnerResult> { + base: &'r mut (dyn PartialReflect + Send + Sync), + ) -> InnerResult> { use ReflectMut::*; let invalid_variant = diff --git a/crates/bevy_reflect/src/path/mod.rs b/crates/bevy_reflect/src/path/mod.rs index a52bbb6aaa688..68824fdffb9ea 100644 --- a/crates/bevy_reflect/src/path/mod.rs +++ b/crates/bevy_reflect/src/path/mod.rs @@ -52,20 +52,26 @@ pub trait ReflectPath<'a>: Sized { /// /// See [`GetPath::reflect_path`] for more details, /// see [`element`](Self::element) if you want a typed return value. - fn reflect_element(self, root: &dyn PartialReflect) -> PathResult<'a, &dyn PartialReflect>; + fn reflect_element( + self, + root: &(dyn PartialReflect + Send + Sync), + ) -> PathResult<'a, &(dyn PartialReflect + Send + Sync)>; /// Gets a mutable reference to the specified element on the given [`Reflect`] object. /// /// See [`GetPath::reflect_path_mut`] for more details. fn reflect_element_mut( self, - root: &mut dyn PartialReflect, - ) -> PathResult<'a, &mut dyn PartialReflect>; + root: &mut (dyn PartialReflect + Send + Sync), + ) -> PathResult<'a, &mut (dyn PartialReflect + Send + Sync)>; /// Gets a `&T` to the specified element on the given [`Reflect`] object. /// /// See [`GetPath::path`] for more details. - fn element(self, root: &dyn PartialReflect) -> PathResult<'a, &T> { + fn element( + self, + root: &(dyn PartialReflect + Send + Sync), + ) -> PathResult<'a, &T> { self.reflect_element(root).and_then(|p| { p.try_downcast_ref::() .ok_or(ReflectPathError::InvalidDowncast) @@ -75,7 +81,10 @@ pub trait ReflectPath<'a>: Sized { /// Gets a `&mut T` to the specified element on the given [`Reflect`] object. /// /// See [`GetPath::path_mut`] for more details. - fn element_mut(self, root: &mut dyn PartialReflect) -> PathResult<'a, &mut T> { + fn element_mut( + self, + root: &mut (dyn PartialReflect + Send + Sync), + ) -> PathResult<'a, &mut T> { self.reflect_element_mut(root).and_then(|p| { p.try_downcast_mut::() .ok_or(ReflectPathError::InvalidDowncast) @@ -83,7 +92,10 @@ pub trait ReflectPath<'a>: Sized { } } impl<'a> ReflectPath<'a> for &'a str { - fn reflect_element(self, mut root: &dyn PartialReflect) -> PathResult<'a, &dyn PartialReflect> { + fn reflect_element( + self, + mut root: &(dyn PartialReflect + Send + Sync), + ) -> PathResult<'a, &(dyn PartialReflect + Send + Sync)> { for (access, offset) in PathParser::new(self) { let a = access?; root = a.element(root, Some(offset))?; @@ -92,8 +104,8 @@ impl<'a> ReflectPath<'a> for &'a str { } fn reflect_element_mut( self, - mut root: &mut dyn PartialReflect, - ) -> PathResult<'a, &mut dyn PartialReflect> { + mut root: &mut (dyn PartialReflect + Send + Sync), + ) -> PathResult<'a, &mut (dyn PartialReflect + Send + Sync)> { for (access, offset) in PathParser::new(self) { root = access?.element_mut(root, Some(offset))?; } @@ -252,7 +264,10 @@ pub trait GetPath: PartialReflect { /// /// To retrieve a statically typed reference, use /// [`path`][GetPath::path]. - fn reflect_path<'p>(&self, path: impl ReflectPath<'p>) -> PathResult<'p, &dyn PartialReflect> { + fn reflect_path<'p>( + &self, + path: impl ReflectPath<'p>, + ) -> PathResult<'p, &(dyn PartialReflect + Send + Sync)> { path.reflect_element(self.as_partial_reflect()) } @@ -263,7 +278,7 @@ pub trait GetPath: PartialReflect { fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, - ) -> PathResult<'p, &mut dyn PartialReflect> { + ) -> PathResult<'p, &mut (dyn PartialReflect + Send + Sync)> { path.reflect_element_mut(self.as_partial_reflect_mut()) } @@ -274,7 +289,10 @@ pub trait GetPath: PartialReflect { /// (which may be the case when using dynamic types like [`DynamicStruct`]). /// /// [`DynamicStruct`]: crate::DynamicStruct - fn path<'p, T: Reflect>(&self, path: impl ReflectPath<'p>) -> PathResult<'p, &T> { + fn path<'p, T: Reflect + Send + Sync + Send + Sync>( + &self, + path: impl ReflectPath<'p>, + ) -> PathResult<'p, &T> { path.element(self.as_partial_reflect()) } @@ -285,13 +303,16 @@ pub trait GetPath: PartialReflect { /// (which may be the case when using dynamic types like [`DynamicStruct`]). /// /// [`DynamicStruct`]: crate::DynamicStruct - fn path_mut<'p, T: Reflect>(&mut self, path: impl ReflectPath<'p>) -> PathResult<'p, &mut T> { + fn path_mut<'p, T: Reflect + Send + Sync + Send + Sync>( + &mut self, + path: impl ReflectPath<'p>, + ) -> PathResult<'p, &mut T> { path.element_mut(self.as_partial_reflect_mut()) } } // Implement `GetPath` for `dyn Reflect` -impl GetPath for T {} +impl GetPath for T {} /// An [`Access`] combined with an `offset` for more helpful error reporting. #[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash)] @@ -438,7 +459,10 @@ impl ParsedPath { } } impl<'a> ReflectPath<'a> for &'a ParsedPath { - fn reflect_element(self, mut root: &dyn PartialReflect) -> PathResult<'a, &dyn PartialReflect> { + fn reflect_element( + self, + mut root: &(dyn PartialReflect + Send + Sync), + ) -> PathResult<'a, &(dyn PartialReflect + Send + Sync)> { for OffsetAccess { access, offset } in &self.0 { root = access.element(root, *offset)?; } @@ -446,8 +470,8 @@ impl<'a> ReflectPath<'a> for &'a ParsedPath { } fn reflect_element_mut( self, - mut root: &mut dyn PartialReflect, - ) -> PathResult<'a, &mut dyn PartialReflect> { + mut root: &mut (dyn PartialReflect + Send + Sync), + ) -> PathResult<'a, &mut (dyn PartialReflect + Send + Sync)> { for OffsetAccess { access, offset } in &self.0 { root = access.element_mut(root, *offset)?; } diff --git a/crates/bevy_reflect/src/reflect.rs b/crates/bevy_reflect/src/reflect.rs index 4918179e127f4..fbbd1e4cc960e 100644 --- a/crates/bevy_reflect/src/reflect.rs +++ b/crates/bevy_reflect/src/reflect.rs @@ -81,7 +81,7 @@ impl From for ApplyError { message = "`{Self}` does not implement `PartialReflect` so cannot be introspected", note = "consider annotating `{Self}` with `#[derive(Reflect)]`" )] -pub trait PartialReflect: DynamicTypePath + Send + Sync +pub trait PartialReflect: DynamicTypePath where // NB: we don't use `Self: Any` since for downcasting, `Reflect` should be used. Self: 'static, @@ -106,32 +106,34 @@ where /// Casts this type to a boxed, reflected value. /// /// This is useful for coercing trait objects. - fn into_partial_reflect(self: Box) -> Box; + fn into_partial_reflect(self: Box) -> Box; /// Casts this type to a reflected value. /// /// This is useful for coercing trait objects. - fn as_partial_reflect(&self) -> &dyn PartialReflect; + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync); /// Casts this type to a mutable, reflected value. /// /// This is useful for coercing trait objects. - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect; + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync); /// Attempts to cast this type to a boxed, [fully-reflected] value. /// /// [fully-reflected]: Reflect - fn try_into_reflect(self: Box) -> Result, Box>; + fn try_into_reflect( + self: Box, + ) -> Result, Box>; /// Attempts to cast this type to a [fully-reflected] value. /// /// [fully-reflected]: Reflect - fn try_as_reflect(&self) -> Option<&dyn Reflect>; + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)>; /// Attempts to cast this type to a mutable, [fully-reflected] value. /// /// [fully-reflected]: Reflect - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>; + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)>; /// Applies a reflected value to this value. /// @@ -181,7 +183,7 @@ where /// - If `T` is any complex type and the corresponding fields or elements of /// `self` and `value` are not of the same type. /// - If `T` is an opaque type and `self` cannot be downcast to `T` - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { PartialReflect::try_apply(self, value).unwrap(); } @@ -194,7 +196,7 @@ where /// /// This function may leave `self` in a partially mutated state if a error was encountered on the way. /// consider maintaining a cloned instance of this data you can switch to if a error is encountered. - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError>; + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError>; /// Returns a zero-sized enumeration of "kinds" of type. /// @@ -250,7 +252,7 @@ where since = "0.16.0", note = "to clone reflected values, prefer using `reflect_clone`. To convert reflected values to dynamic ones, use `to_dynamic`." )] - fn clone_value(&self) -> Box { + fn clone_value(&self) -> Box { self.to_dynamic() } @@ -288,7 +290,7 @@ where /// [`DynamicStruct`]: crate::DynamicStruct /// [opaque]: crate::ReflectKind::Opaque /// [`reflect_clone`]: PartialReflect::reflect_clone - fn to_dynamic(&self) -> Box { + fn to_dynamic(&self) -> Box { match self.reflect_ref() { ReflectRef::Struct(dyn_struct) => Box::new(dyn_struct.to_dynamic_struct()), ReflectRef::TupleStruct(dyn_tuple_struct) => { @@ -323,7 +325,7 @@ where /// ``` /// /// [`to_dynamic`]: PartialReflect::to_dynamic - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { Err(ReflectCloneError::NotImplemented { type_path: Cow::Owned(self.reflect_type_path().to_string()), }) @@ -339,7 +341,7 @@ where /// Returns a "partial equality" comparison result. /// /// If the underlying type does not support equality testing, returns `None`. - fn reflect_partial_eq(&self, _value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, _value: &(dyn PartialReflect + Send + Sync)) -> Option { None } @@ -427,28 +429,31 @@ pub trait Reflect: PartialReflect + DynamicTyped + Any { fn as_any_mut(&mut self) -> &mut dyn Any; /// Casts this type to a boxed, fully-reflected value. - fn into_reflect(self: Box) -> Box; + fn into_reflect(self: Box) -> Box; /// Casts this type to a fully-reflected value. - fn as_reflect(&self) -> &dyn Reflect; + fn as_reflect(&self) -> &(dyn Reflect + Send + Sync); /// Casts this type to a mutable, fully-reflected value. - fn as_reflect_mut(&mut self) -> &mut dyn Reflect; + fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + Send + Sync); /// Performs a type-checked assignment of a reflected value to this value. /// /// If `value` does not contain a value of type `T`, returns an `Err` /// containing the trait object. - fn set(&mut self, value: Box) -> Result<(), Box>; + fn set( + &mut self, + value: Box, + ) -> Result<(), Box>; } -impl dyn PartialReflect { +impl dyn PartialReflect + Send + Sync { /// Returns `true` if the underlying value represents a value of type `T`, or `false` /// otherwise. /// /// Read `is` for more information on underlying values and represented types. #[inline] - pub fn represents(&self) -> bool { + pub fn represents(&self) -> bool { self.get_represented_type_info() .is_some_and(|t| t.type_path() == T::type_path()) } @@ -460,8 +465,8 @@ impl dyn PartialReflect { /// /// For remote types, `T` should be the type itself rather than the wrapper type. pub fn try_downcast( - self: Box, - ) -> Result, Box> { + self: Box, + ) -> Result, Box> { self.try_into_reflect()? .downcast() .map_err(PartialReflect::into_partial_reflect) @@ -473,7 +478,9 @@ impl dyn PartialReflect { /// or is not of type `T`, returns `Err(self)`. /// /// For remote types, `T` should be the type itself rather than the wrapper type. - pub fn try_take(self: Box) -> Result> { + pub fn try_take( + self: Box, + ) -> Result> { self.try_downcast().map(|value| *value) } @@ -498,7 +505,7 @@ impl dyn PartialReflect { } } -impl Debug for dyn PartialReflect { +impl Debug for dyn PartialReflect + Send + Sync { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { self.debug(f) } @@ -506,24 +513,26 @@ impl Debug for dyn PartialReflect { // The following implementation never actually shadows the concrete TypePath implementation. // See the comment on `dyn Reflect`'s `TypePath` implementation. -impl TypePath for dyn PartialReflect { +impl TypePath for dyn PartialReflect + Send + Sync { fn type_path() -> &'static str { - "dyn bevy_reflect::PartialReflect" + "dyn bevy_reflect::PartialReflect + Send + Sync" } fn short_type_path() -> &'static str { - "dyn PartialReflect" + "dyn PartialReflect + Send + Sync" } } #[deny(rustdoc::broken_intra_doc_links)] -impl dyn Reflect { +impl dyn Reflect + Send + Sync { /// Downcasts the value to type `T`, consuming the trait object. /// /// If the underlying value is not of type `T`, returns `Err(self)`. /// /// For remote types, `T` should be the type itself rather than the wrapper type. - pub fn downcast(self: Box) -> Result, Box> { + pub fn downcast( + self: Box, + ) -> Result, Box> { if self.is::() { Ok(self.into_any().downcast().unwrap()) } else { @@ -536,7 +545,9 @@ impl dyn Reflect { /// If the underlying value is not of type `T`, returns `Err(self)`. /// /// For remote types, `T` should be the type itself rather than the wrapper type. - pub fn take(self: Box) -> Result> { + pub fn take( + self: Box, + ) -> Result> { self.downcast::().map(|value| *value) } @@ -578,13 +589,13 @@ impl dyn Reflect { } } -impl Debug for dyn Reflect { +impl Debug for dyn Reflect + Send + Sync { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { self.debug(f) } } -impl Typed for dyn Reflect { +impl Typed for dyn Reflect + Send + Sync { fn type_info() -> &'static TypeInfo { static CELL: NonGenericTypeInfoCell = NonGenericTypeInfoCell::new(); CELL.get_or_set(|| TypeInfo::Opaque(OpaqueInfo::new::())) @@ -593,7 +604,7 @@ impl Typed for dyn Reflect { // The following implementation never actually shadows the concrete `TypePath` implementation. // See this playground (https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=589064053f27bc100d90da89c6a860aa). -impl TypePath for dyn Reflect { +impl TypePath for dyn Reflect + Send + Sync { fn type_path() -> &'static str { "dyn bevy_reflect::Reflect" } @@ -618,23 +629,23 @@ macro_rules! impl_full_reflect { self } - fn into_reflect(self: Box) -> Box { + fn into_reflect(self: Box) -> Box { self } - fn as_reflect(&self) -> &dyn $crate::Reflect { + fn as_reflect(&self) -> &(dyn $crate::Reflect + Send + Sync) { self } - fn as_reflect_mut(&mut self) -> &mut dyn $crate::Reflect { + fn as_reflect_mut(&mut self) -> &mut (dyn $crate::Reflect + Send + Sync) { self } fn set( &mut self, - value: Box, - ) -> Result<(), Box> { - *self = ::take(value)?; + value: Box, + ) -> Result<(), Box> { + *self = ::take(value)?; Ok(()) } } diff --git a/crates/bevy_reflect/src/reflectable.rs b/crates/bevy_reflect/src/reflectable.rs index 08226bc214747..4b91d7dce9676 100644 --- a/crates/bevy_reflect/src/reflectable.rs +++ b/crates/bevy_reflect/src/reflectable.rs @@ -30,4 +30,4 @@ use crate::{GetTypeRegistration, Reflect, TypePath, Typed}; /// [`Reflect` derive macro]: bevy_reflect_derive::Reflect pub trait Reflectable: Reflect + GetTypeRegistration + Typed + TypePath {} -impl Reflectable for T {} +impl Reflectable for T {} diff --git a/crates/bevy_reflect/src/serde/de/deserialize_with_registry.rs b/crates/bevy_reflect/src/serde/de/deserialize_with_registry.rs index f92a8e68e24da..d5a11c483bca0 100644 --- a/crates/bevy_reflect/src/serde/de/deserialize_with_registry.rs +++ b/crates/bevy_reflect/src/serde/de/deserialize_with_registry.rs @@ -53,7 +53,7 @@ pub struct ReflectDeserializeWithRegistry { deserialize: fn( deserializer: &mut dyn erased_serde::Deserializer, registry: &TypeRegistry, - ) -> Result, erased_serde::Error>, + ) -> Result, erased_serde::Error>, } impl ReflectDeserializeWithRegistry { @@ -62,7 +62,7 @@ impl ReflectDeserializeWithRegistry { &self, deserializer: D, registry: &TypeRegistry, - ) -> Result, D::Error> + ) -> Result, D::Error> where D: Deserializer<'de>, { @@ -71,7 +71,7 @@ impl ReflectDeserializeWithRegistry { } } -impl DeserializeWithRegistry<'de>> FromType +impl DeserializeWithRegistry<'de>> FromType for ReflectDeserializeWithRegistry { fn from_type() -> Self { diff --git a/crates/bevy_reflect/src/serde/de/deserializer.rs b/crates/bevy_reflect/src/serde/de/deserializer.rs index 1c20eaad07abc..50d7cb7fba714 100644 --- a/crates/bevy_reflect/src/serde/de/deserializer.rs +++ b/crates/bevy_reflect/src/serde/de/deserializer.rs @@ -32,11 +32,11 @@ use super::ReflectDeserializerProcessor; /// /// # Output /// -/// This deserializer will return a [`Box`] containing the deserialized data. +/// This deserializer will return a [`Box`] containing the deserialized data. /// /// For opaque types (i.e. [`ReflectKind::Opaque`]) or types that register [`ReflectDeserialize`] type data, /// this `Box` will contain the expected type. -/// For example, deserializing an `i32` will return a `Box` (as a `Box`). +/// For example, deserializing an `i32` will return a `Box` (as a `Box`). /// /// Otherwise, this `Box` will contain the dynamic equivalent. /// For example, a deserialized struct might return a [`Box`] @@ -73,7 +73,7 @@ use super::ReflectDeserializerProcessor; /// let mut deserializer = ron::Deserializer::from_str(input).unwrap(); /// let reflect_deserializer = ReflectDeserializer::new(®istry); /// -/// let output: Box = reflect_deserializer.deserialize(&mut deserializer).unwrap(); +/// let output: Box = reflect_deserializer.deserialize(&mut deserializer).unwrap(); /// /// // Since `MyStruct` is not an opaque type and does not register `ReflectDeserialize`, /// // we know that its deserialized value will be a `DynamicStruct`, @@ -87,14 +87,14 @@ use super::ReflectDeserializerProcessor; /// // We can also do this dynamically with `ReflectFromReflect`. /// let type_id = output.get_represented_type_info().unwrap().type_id(); /// let reflect_from_reflect = registry.get_type_data::(type_id).unwrap(); -/// let value: Box = reflect_from_reflect.from_reflect(output.as_partial_reflect()).unwrap(); +/// let value: Box = reflect_from_reflect.from_reflect(output.as_partial_reflect()).unwrap(); /// assert!(value.is::()); /// assert_eq!(value.take::().unwrap(), MyStruct { value: 123 }); /// ``` /// /// [`ReflectSerializer`]: crate::serde::ReflectSerializer /// [type path]: crate::TypePath::type_path -/// [`Box`]: crate::Reflect +/// [`Box`]: crate::Reflect /// [`ReflectKind::Opaque`]: crate::ReflectKind::Opaque /// [`ReflectDeserialize`]: crate::ReflectDeserialize /// [`Box`]: crate::DynamicStruct @@ -138,7 +138,7 @@ impl<'a, P: ReflectDeserializerProcessor> ReflectDeserializer<'a, P> { } impl<'de, P: ReflectDeserializerProcessor> DeserializeSeed<'de> for ReflectDeserializer<'_, P> { - type Value = Box; + type Value = Box; fn deserialize(self, deserializer: D) -> Result where @@ -152,7 +152,7 @@ impl<'de, P: ReflectDeserializerProcessor> DeserializeSeed<'de> for ReflectDeser impl<'de, P: ReflectDeserializerProcessor> Visitor<'de> for UntypedReflectDeserializerVisitor<'_, P> { - type Value = Box; + type Value = Box; fn expecting(&self, formatter: &mut Formatter) -> fmt::Result { formatter @@ -200,11 +200,11 @@ impl<'de, P: ReflectDeserializerProcessor> DeserializeSeed<'de> for ReflectDeser /// /// # Output /// -/// This deserializer will return a [`Box`] containing the deserialized data. +/// This deserializer will return a [`Box`] containing the deserialized data. /// /// For opaque types (i.e. [`ReflectKind::Opaque`]) or types that register [`ReflectDeserialize`] type data, /// this `Box` will contain the expected type. -/// For example, deserializing an `i32` will return a `Box` (as a `Box`). +/// For example, deserializing an `i32` will return a `Box` (as a `Box`). /// /// Otherwise, this `Box` will contain the dynamic equivalent. /// For example, a deserialized struct might return a [`Box`] @@ -241,7 +241,7 @@ impl<'de, P: ReflectDeserializerProcessor> DeserializeSeed<'de> for ReflectDeser /// let mut deserializer = ron::Deserializer::from_str(input).unwrap(); /// let reflect_deserializer = TypedReflectDeserializer::new(registration, ®istry); /// -/// let output: Box = reflect_deserializer.deserialize(&mut deserializer).unwrap(); +/// let output: Box = reflect_deserializer.deserialize(&mut deserializer).unwrap(); /// /// // Since `MyStruct` is not an opaque type and does not register `ReflectDeserialize`, /// // we know that its deserialized value will be a `DynamicStruct`, @@ -255,13 +255,13 @@ impl<'de, P: ReflectDeserializerProcessor> DeserializeSeed<'de> for ReflectDeser /// // We can also do this dynamically with `ReflectFromReflect`. /// let type_id = output.get_represented_type_info().unwrap().type_id(); /// let reflect_from_reflect = registry.get_type_data::(type_id).unwrap(); -/// let value: Box = reflect_from_reflect.from_reflect(output.as_partial_reflect()).unwrap(); +/// let value: Box = reflect_from_reflect.from_reflect(output.as_partial_reflect()).unwrap(); /// assert!(value.is::()); /// assert_eq!(value.take::().unwrap(), MyStruct { value: 123 }); /// ``` /// /// [`TypedReflectSerializer`]: crate::serde::TypedReflectSerializer -/// [`Box`]: crate::Reflect +/// [`Box`]: crate::Reflect /// [`ReflectKind::Opaque`]: crate::ReflectKind::Opaque /// [`ReflectDeserialize`]: crate::ReflectDeserialize /// [`Box`]: crate::DynamicStruct @@ -351,7 +351,7 @@ impl<'a, P: ReflectDeserializerProcessor> TypedReflectDeserializer<'a, P> { impl<'de, P: ReflectDeserializerProcessor> DeserializeSeed<'de> for TypedReflectDeserializer<'_, P> { - type Value = Box; + type Value = Box; fn deserialize(mut self, deserializer: D) -> Result where diff --git a/crates/bevy_reflect/src/serde/de/mod.rs b/crates/bevy_reflect/src/serde/de/mod.rs index c11e75dec101b..49874f6bea1b9 100644 --- a/crates/bevy_reflect/src/serde/de/mod.rs +++ b/crates/bevy_reflect/src/serde/de/mod.rs @@ -541,7 +541,7 @@ mod tests { registration: &TypeRegistration, _: &TypeRegistry, deserializer: D, - ) -> Result, D>, D::Error> + ) -> Result, D>, D::Error> where D: Deserializer<'de>, { @@ -593,7 +593,7 @@ mod tests { registration: &TypeRegistration, _: &TypeRegistry, deserializer: D, - ) -> Result, D>, D::Error> + ) -> Result, D>, D::Error> where D: Deserializer<'de>, { @@ -642,7 +642,7 @@ mod tests { registration: &TypeRegistration, _: &TypeRegistry, deserializer: D, - ) -> Result, D>, D::Error> + ) -> Result, D>, D::Error> where D: Deserializer<'de>, { @@ -688,7 +688,7 @@ mod tests { _: &TypeRegistration, _: &TypeRegistry, deserializer: D, - ) -> Result, D>, D::Error> + ) -> Result, D>, D::Error> where D: Deserializer<'de>, { @@ -730,7 +730,7 @@ mod tests { registration: &TypeRegistration, _registry: &TypeRegistry, deserializer: D, - ) -> Result, D>, D::Error> + ) -> Result, D>, D::Error> where D: Deserializer<'de>, { diff --git a/crates/bevy_reflect/src/serde/de/processor.rs b/crates/bevy_reflect/src/serde/de/processor.rs index 98bcfa09b55b9..264029e2fa78c 100644 --- a/crates/bevy_reflect/src/serde/de/processor.rs +++ b/crates/bevy_reflect/src/serde/de/processor.rs @@ -13,7 +13,7 @@ use alloc::boxed::Box; /// /// Whenever the deserializer attempts to deserialize a value, it will first /// call [`try_deserialize`] on your processor, which may take ownership of the -/// deserializer and give back a [`Box`], or return +/// deserializer and give back a [`Box`], or return /// ownership of the deserializer back, and continue with the default logic. /// /// The serialization equivalent of this is [`ReflectSerializerProcessor`]. @@ -49,7 +49,7 @@ use alloc::boxed::Box; /// # #[derive(Debug, Clone, Reflect)] /// # struct LoadedUntypedAsset; /// # #[derive(Debug, Clone, Reflect)] -/// # struct Handle(T); +/// # struct Handle(T); /// # #[derive(Debug, Clone, Reflect)] /// # struct Mesh; /// # @@ -100,7 +100,7 @@ use alloc::boxed::Box; /// registration: &TypeRegistration, /// _registry: &TypeRegistry, /// deserializer: D, -/// ) -> Result, D>, D::Error> +/// ) -> Result, D>, D::Error> /// where /// D: Deserializer<'de>, /// { @@ -147,7 +147,7 @@ pub trait ReflectDeserializerProcessor { /// that you want to assign this value to. The type inside the box must /// be the same one as the `registration` is for, otherwise future /// reflection operations (such as using [`FromReflect`] to convert the - /// resulting [`Box`] into a concrete type) will fail. + /// resulting [`Box`] into a concrete type) will fail. /// /// If you don't want to override the deserialization, return ownership of /// the deserializer back via `Ok(Err(deserializer))`. @@ -176,7 +176,7 @@ pub trait ReflectDeserializerProcessor { /// registration: &TypeRegistration, /// _registry: &TypeRegistry, /// deserializer: D, - /// ) -> Result, D>, D::Error> + /// ) -> Result, D>, D::Error> /// where /// D: serde::Deserializer<'de> /// { @@ -197,7 +197,7 @@ pub trait ReflectDeserializerProcessor { registration: &TypeRegistration, registry: &TypeRegistry, deserializer: D, - ) -> Result, D>, D::Error> + ) -> Result, D>, D::Error> where D: serde::Deserializer<'de>; } @@ -208,7 +208,7 @@ impl ReflectDeserializerProcessor for () { _registration: &TypeRegistration, _registry: &TypeRegistry, deserializer: D, - ) -> Result, D>, D::Error> + ) -> Result, D>, D::Error> where D: serde::Deserializer<'de>, { diff --git a/crates/bevy_reflect/src/serde/mod.rs b/crates/bevy_reflect/src/serde/mod.rs index 2d912fd97bd15..8d003018c8478 100644 --- a/crates/bevy_reflect/src/serde/mod.rs +++ b/crates/bevy_reflect/src/serde/mod.rs @@ -199,7 +199,7 @@ mod tests { use serde::{Deserializer, Serialize, Serializer}; #[reflect_trait] - trait Enemy: Reflect + Debug { + trait Enemy: Reflect + Send + Sync + Debug { #[expect(dead_code, reason = "this method is purely for testing purposes")] fn hp(&self) -> u8; } @@ -449,7 +449,9 @@ mod tests { let nested_tuple_struct_with_skip = Enum::NestedTupleStructWithSkip(TupleStructWithSkip(6, 7)); - fn assert_serialize( + fn assert_serialize< + T: Reflect + Send + Sync + FromReflect + Send + Sync + Serialize + PartialEq + Debug, + >( value: &T, registry: &TypeRegistry, ) { diff --git a/crates/bevy_reflect/src/serde/ser/custom_serialization.rs b/crates/bevy_reflect/src/serde/ser/custom_serialization.rs index 18d2abed9c010..a80142c631720 100644 --- a/crates/bevy_reflect/src/serde/ser/custom_serialization.rs +++ b/crates/bevy_reflect/src/serde/ser/custom_serialization.rs @@ -12,7 +12,7 @@ use serde::{Serialize, Serializer}; /// On success, returns the result of the serialization. /// On failure, returns the original serializer and the error that occurred. pub(super) fn try_custom_serialize( - value: &dyn PartialReflect, + value: &(dyn PartialReflect + Send + Sync), type_registry: &TypeRegistry, serializer: S, ) -> Result, (S, S::Error)> { diff --git a/crates/bevy_reflect/src/serde/ser/mod.rs b/crates/bevy_reflect/src/serde/ser/mod.rs index 6027a0effad46..fc37cb55138d5 100644 --- a/crates/bevy_reflect/src/serde/ser/mod.rs +++ b/crates/bevy_reflect/src/serde/ser/mod.rs @@ -497,7 +497,7 @@ mod tests { impl ReflectSerializerProcessor for FooProcessor { fn try_serialize( &self, - value: &dyn PartialReflect, + value: &(dyn PartialReflect + Send + Sync), _: &TypeRegistry, serializer: S, ) -> Result, S::Error> @@ -556,7 +556,7 @@ mod tests { impl ReflectSerializerProcessor for FooProcessor { fn try_serialize( &self, - value: &dyn PartialReflect, + value: &(dyn PartialReflect + Send + Sync), _: &TypeRegistry, serializer: S, ) -> Result, S::Error> @@ -610,7 +610,7 @@ mod tests { impl ReflectSerializerProcessor for ErroringProcessor { fn try_serialize( &self, - value: &dyn PartialReflect, + value: &(dyn PartialReflect + Send + Sync), _: &TypeRegistry, serializer: S, ) -> Result, S::Error> @@ -664,7 +664,7 @@ mod tests { func: DynamicFunction<'static>, } - let value: Box = Box::new(MyStruct { + let value: Box = Box::new(MyStruct { func: String::new.into_function(), }); diff --git a/crates/bevy_reflect/src/serde/ser/processor.rs b/crates/bevy_reflect/src/serde/ser/processor.rs index cf31ab7566791..cd6b01baa27ae 100644 --- a/crates/bevy_reflect/src/serde/ser/processor.rs +++ b/crates/bevy_reflect/src/serde/ser/processor.rs @@ -84,7 +84,7 @@ use crate::{PartialReflect, TypeRegistry}; /// impl ReflectSerializerProcessor for HandleProcessor { /// fn try_serialize( /// &self, -/// value: &dyn PartialReflect, +/// value: &(dyn PartialReflect + Send + Sync), /// registry: &TypeRegistry, /// serializer: S, /// ) -> Result, S::Error> @@ -151,7 +151,7 @@ pub trait ReflectSerializerProcessor { /// impl ReflectSerializerProcessor for I32AsStringProcessor { /// fn try_serialize( /// &self, - /// value: &dyn PartialReflect, + /// value: &(dyn PartialReflect + Send + Sync), /// registry: &TypeRegistry, /// serializer: S, /// ) -> Result, S::Error> @@ -173,7 +173,7 @@ pub trait ReflectSerializerProcessor { /// [`Reflect`]: crate::Reflect fn try_serialize( &self, - value: &dyn PartialReflect, + value: &(dyn PartialReflect + Send + Sync), registry: &TypeRegistry, serializer: S, ) -> Result, S::Error> @@ -184,7 +184,7 @@ pub trait ReflectSerializerProcessor { impl ReflectSerializerProcessor for () { fn try_serialize( &self, - _value: &dyn PartialReflect, + _value: &(dyn PartialReflect + Send + Sync), _registry: &TypeRegistry, serializer: S, ) -> Result, S::Error> diff --git a/crates/bevy_reflect/src/serde/ser/serialize_with_registry.rs b/crates/bevy_reflect/src/serde/ser/serialize_with_registry.rs index 9c5bfb06f1ca8..597b29ebbfb2c 100644 --- a/crates/bevy_reflect/src/serde/ser/serialize_with_registry.rs +++ b/crates/bevy_reflect/src/serde/ser/serialize_with_registry.rs @@ -49,7 +49,7 @@ pub trait SerializeWithRegistry { #[derive(Clone)] pub struct ReflectSerializeWithRegistry { serialize: for<'a> fn( - value: &'a dyn Reflect, + value: &'a (dyn Reflect + Send + Sync), registry: &'a TypeRegistry, ) -> Box, } @@ -58,7 +58,7 @@ impl ReflectSerializeWithRegistry { /// Serialize a [`Reflect`] type with this type data's custom [`SerializeWithRegistry`] implementation. pub fn serialize( &self, - value: &dyn Reflect, + value: &(dyn Reflect + Send + Sync), serializer: S, registry: &TypeRegistry, ) -> Result @@ -69,10 +69,12 @@ impl ReflectSerializeWithRegistry { } } -impl FromType for ReflectSerializeWithRegistry { +impl FromType + for ReflectSerializeWithRegistry +{ fn from_type() -> Self { Self { - serialize: |value: &dyn Reflect, registry| { + serialize: |value: &(dyn Reflect + Send + Sync), registry| { let value = value.downcast_ref::().unwrap_or_else(|| { panic!( "Expected value to be of type {} but received {}", diff --git a/crates/bevy_reflect/src/serde/ser/serializer.rs b/crates/bevy_reflect/src/serde/ser/serializer.rs index afe6b56b1dfaf..7b8e83601aaa2 100644 --- a/crates/bevy_reflect/src/serde/ser/serializer.rs +++ b/crates/bevy_reflect/src/serde/ser/serializer.rs @@ -55,7 +55,7 @@ use super::ReflectSerializerProcessor; /// [type path]: crate::TypePath::type_path /// [`with_processor`]: Self::with_processor pub struct ReflectSerializer<'a, P = ()> { - value: &'a dyn PartialReflect, + value: &'a (dyn PartialReflect + Send + Sync), registry: &'a TypeRegistry, processor: Option<&'a P>, } @@ -67,7 +67,7 @@ impl<'a> ReflectSerializer<'a, ()> { /// [`with_processor`]. /// /// [`with_processor`]: Self::with_processor - pub fn new(value: &'a dyn PartialReflect, registry: &'a TypeRegistry) -> Self { + pub fn new(value: &'a (dyn PartialReflect + Send + Sync), registry: &'a TypeRegistry) -> Self { Self { value, registry, @@ -84,7 +84,7 @@ impl<'a, P: ReflectSerializerProcessor> ReflectSerializer<'a, P> { /// /// [`new`]: Self::new pub fn with_processor( - value: &'a dyn PartialReflect, + value: &'a (dyn PartialReflect + Send + Sync), registry: &'a TypeRegistry, processor: &'a P, ) -> Self { @@ -169,7 +169,7 @@ impl Serialize for ReflectSerializer<'_, P> { /// [type path]: crate::TypePath::type_path /// [`with_processor`]: Self::with_processor pub struct TypedReflectSerializer<'a, P = ()> { - value: &'a dyn PartialReflect, + value: &'a (dyn PartialReflect + Send + Sync), registry: &'a TypeRegistry, processor: Option<&'a P>, } @@ -181,7 +181,7 @@ impl<'a> TypedReflectSerializer<'a, ()> { /// [`with_processor`]. /// /// [`with_processor`]: Self::with_processor - pub fn new(value: &'a dyn PartialReflect, registry: &'a TypeRegistry) -> Self { + pub fn new(value: &'a (dyn PartialReflect + Send + Sync), registry: &'a TypeRegistry) -> Self { #[cfg(feature = "debug_stack")] TYPE_INFO_STACK.set(crate::type_info_stack::TypeInfoStack::new()); @@ -201,7 +201,7 @@ impl<'a, P> TypedReflectSerializer<'a, P> { /// /// [`new`]: Self::new pub fn with_processor( - value: &'a dyn PartialReflect, + value: &'a (dyn PartialReflect + Send + Sync), registry: &'a TypeRegistry, processor: &'a P, ) -> Self { @@ -217,7 +217,7 @@ impl<'a, P> TypedReflectSerializer<'a, P> { /// An internal constructor for creating a serializer without resetting the type info stack. pub(super) fn new_internal( - value: &'a dyn PartialReflect, + value: &'a (dyn PartialReflect + Send + Sync), registry: &'a TypeRegistry, processor: Option<&'a P>, ) -> Self { diff --git a/crates/bevy_reflect/src/serde/type_data.rs b/crates/bevy_reflect/src/serde/type_data.rs index f1b0129a3c468..b94c1713af712 100644 --- a/crates/bevy_reflect/src/serde/type_data.rs +++ b/crates/bevy_reflect/src/serde/type_data.rs @@ -87,7 +87,7 @@ impl SerializationData { /// let serialization_data = registry.get_type_data::(TypeId::of::()).unwrap(); /// assert_eq!(789, serialization_data.generate_default(1).unwrap().take::().unwrap()); /// ``` - pub fn generate_default(&self, index: usize) -> Option> { + pub fn generate_default(&self, index: usize) -> Option> { self.skipped_fields .get(&index) .map(SkippedField::generate_default) @@ -107,7 +107,7 @@ impl SerializationData { /// /// Each item in the iterator is a tuple containing: /// 1. The reflected index of the field - /// 2. The (de)serialization metadata of the field + /// 2. The (de)serialization metadata of the field pub fn iter_skipped(&self) -> Iter<'_, usize, SkippedField> { self.skipped_fields.iter() } @@ -116,7 +116,7 @@ impl SerializationData { /// Data needed for (de)serialization of a skipped field. #[derive(Debug, Clone)] pub struct SkippedField { - default_fn: fn() -> Box, + default_fn: fn() -> Box, } impl SkippedField { @@ -125,12 +125,12 @@ impl SkippedField { /// # Arguments /// /// * `default_fn`: A function pointer used to generate a default instance of the field. - pub fn new(default_fn: fn() -> Box) -> Self { + pub fn new(default_fn: fn() -> Box) -> Self { Self { default_fn } } /// Generates a default instance of the field. - pub fn generate_default(&self) -> Box { + pub fn generate_default(&self) -> Box { (self.default_fn)() } } diff --git a/crates/bevy_reflect/src/set.rs b/crates/bevy_reflect/src/set.rs index 21aa7a4d20cea..ab10fe1674e62 100644 --- a/crates/bevy_reflect/src/set.rs +++ b/crates/bevy_reflect/src/set.rs @@ -39,7 +39,7 @@ use crate::{ /// foo.insert_boxed(Box::new(123_u32)); /// assert_eq!(foo.len(), 1); /// -/// let field: &dyn PartialReflect = foo.get(&123_u32).unwrap(); +/// let field: &(dyn PartialReflect + Send + Sync) = foo.get(&123_u32).unwrap(); /// assert_eq!(field.try_downcast_ref::(), Some(&123_u32)); /// ``` /// @@ -51,7 +51,10 @@ pub trait Set: PartialReflect { /// Returns a reference to the value. /// /// If no value is contained, returns `None`. - fn get(&self, value: &dyn PartialReflect) -> Option<&dyn PartialReflect>; + fn get( + &self, + value: &(dyn PartialReflect + Send + Sync), + ) -> Option<&(dyn PartialReflect + Send + Sync)>; /// Returns the number of elements in the set. fn len(&self) -> usize; @@ -62,12 +65,12 @@ pub trait Set: PartialReflect { } /// Returns an iterator over the values of the set. - fn iter(&self) -> Box + '_>; + fn iter(&self) -> Box + '_>; /// Drain the values of this set to get a vector of owned values. /// /// After calling this function, `self` will be empty. - fn drain(&mut self) -> Vec>; + fn drain(&mut self) -> Vec>; /// Clones the set, producing a [`DynamicSet`]. #[deprecated(since = "0.16.0", note = "use `to_dynamic_set` instead")] @@ -89,16 +92,16 @@ pub trait Set: PartialReflect { /// /// If the set did not have this value present, `true` is returned. /// If the set did have this value present, `false` is returned. - fn insert_boxed(&mut self, value: Box) -> bool; + fn insert_boxed(&mut self, value: Box) -> bool; /// Removes a value from the set. /// /// If the set did not have this value present, `true` is returned. /// If the set did have this value present, `false` is returned. - fn remove(&mut self, value: &dyn PartialReflect) -> bool; + fn remove(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> bool; /// Checks if the given value is contained in the set - fn contains(&self, value: &dyn PartialReflect) -> bool; + fn contains(&self, value: &(dyn PartialReflect + Send + Sync)) -> bool; } /// A container for compile-time set info. @@ -113,7 +116,7 @@ pub struct SetInfo { impl SetInfo { /// Create a new [`SetInfo`]. - pub fn new() -> Self { + pub fn new() -> Self { Self { ty: Type::of::(), generics: Generics::new(), @@ -151,7 +154,7 @@ impl SetInfo { #[derive(Default)] pub struct DynamicSet { represented_type: Option<&'static TypeInfo>, - hash_table: HashTable>, + hash_table: HashTable>, } impl DynamicSet { @@ -175,17 +178,17 @@ impl DynamicSet { } /// Inserts a typed value into the set. - pub fn insert(&mut self, value: V) { + pub fn insert(&mut self, value: V) { self.insert_boxed(Box::new(value)); } - fn internal_hash(value: &dyn PartialReflect) -> u64 { + fn internal_hash(value: &(dyn PartialReflect + Send + Sync)) -> u64 { value.reflect_hash().expect(&hash_error!(value)) } fn internal_eq( - value: &dyn PartialReflect, - ) -> impl FnMut(&Box) -> bool + '_ { + value: &(dyn PartialReflect + Send + Sync), + ) -> impl FnMut(&Box) -> bool + '_ { |other| { value .reflect_partial_eq(&**other) @@ -195,7 +198,10 @@ impl DynamicSet { } impl Set for DynamicSet { - fn get(&self, value: &dyn PartialReflect) -> Option<&dyn PartialReflect> { + fn get( + &self, + value: &(dyn PartialReflect + Send + Sync), + ) -> Option<&(dyn PartialReflect + Send + Sync)> { self.hash_table .find(Self::internal_hash(value), Self::internal_eq(value)) .map(|value| &**value) @@ -205,16 +211,16 @@ impl Set for DynamicSet { self.hash_table.len() } - fn iter(&self) -> Box + '_> { + fn iter(&self) -> Box + '_> { let iter = self.hash_table.iter().map(|v| &**v); Box::new(iter) } - fn drain(&mut self) -> Vec> { + fn drain(&mut self) -> Vec> { self.hash_table.drain().collect::>() } - fn insert_boxed(&mut self, value: Box) -> bool { + fn insert_boxed(&mut self, value: Box) -> bool { assert_eq!( value.reflect_partial_eq(&*value), Some(true), @@ -239,14 +245,14 @@ impl Set for DynamicSet { } } - fn remove(&mut self, value: &dyn PartialReflect) -> bool { + fn remove(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> bool { self.hash_table .find_entry(Self::internal_hash(value), Self::internal_eq(value)) .map(HashTableOccupiedEntry::remove) .is_ok() } - fn contains(&self, value: &dyn PartialReflect) -> bool { + fn contains(&self, value: &(dyn PartialReflect + Send + Sync)) -> bool { self.hash_table .find(Self::internal_hash(value), Self::internal_eq(value)) .is_some() @@ -260,40 +266,42 @@ impl PartialReflect for DynamicSet { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } #[inline] - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } #[inline] - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } #[inline] - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Err(self) } #[inline] - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { None } #[inline] - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { None } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { set_apply(self, value); } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { set_try_apply(self, value) } @@ -313,7 +321,7 @@ impl PartialReflect for DynamicSet { ReflectOwned::Set(self) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { set_partial_eq(self, value) } @@ -337,8 +345,8 @@ impl Debug for DynamicSet { } } -impl FromIterator> for DynamicSet { - fn from_iter>>(values: I) -> Self { +impl FromIterator> for DynamicSet { + fn from_iter>>(values: I) -> Self { let mut this = Self { represented_type: None, hash_table: HashTable::new(), @@ -352,7 +360,7 @@ impl FromIterator> for DynamicSet { } } -impl FromIterator for DynamicSet { +impl FromIterator for DynamicSet { fn from_iter>(values: I) -> Self { let mut this = Self { represented_type: None, @@ -368,7 +376,7 @@ impl FromIterator for DynamicSet { } impl IntoIterator for DynamicSet { - type Item = Box; + type Item = Box; type IntoIter = bevy_platform_support::collections::hash_table::IntoIter; fn into_iter(self) -> Self::IntoIter { @@ -377,10 +385,13 @@ impl IntoIterator for DynamicSet { } impl<'a> IntoIterator for &'a DynamicSet { - type Item = &'a dyn PartialReflect; + type Item = &'a (dyn PartialReflect + Send + Sync); type IntoIter = core::iter::Map< - bevy_platform_support::collections::hash_table::Iter<'a, Box>, - fn(&'a Box) -> Self::Item, + bevy_platform_support::collections::hash_table::Iter< + 'a, + Box, + >, + fn(&'a Box) -> Self::Item, >; fn into_iter(self) -> Self::IntoIter { @@ -398,7 +409,7 @@ impl<'a> IntoIterator for &'a DynamicSet { /// /// Returns [`None`] if the comparison couldn't even be performed. #[inline] -pub fn set_partial_eq(a: &M, b: &dyn PartialReflect) -> Option { +pub fn set_partial_eq(a: &M, b: &(dyn PartialReflect + Send + Sync)) -> Option { let ReflectRef::Set(set) = b.reflect_ref() else { return Some(false); }; @@ -430,7 +441,7 @@ pub fn set_partial_eq(a: &M, b: &dyn PartialReflect) -> Option { /// /// let mut my_set = HashSet::new(); /// my_set.insert(String::from("Hello")); -/// println!("{:#?}", &my_set as &dyn Reflect); +/// println!("{:#?}", &my_set as &(dyn Reflect + Send + Sync)); /// /// // Output: /// @@ -455,7 +466,7 @@ pub fn set_debug(dyn_set: &dyn Set, f: &mut Formatter<'_>) -> core::fmt::Result /// /// This function panics if `b` is not a reflected set. #[inline] -pub fn set_apply(a: &mut M, b: &dyn PartialReflect) { +pub fn set_apply(a: &mut M, b: &(dyn PartialReflect + Send + Sync)) { if let ReflectRef::Set(set_value) = b.reflect_ref() { for b_value in set_value.iter() { if a.get(b_value).is_none() { @@ -477,7 +488,10 @@ pub fn set_apply(a: &mut M, b: &dyn PartialReflect) { /// This function returns an [`ApplyError::MismatchedKinds`] if `b` is not a reflected set or if /// applying elements to each other fails. #[inline] -pub fn set_try_apply(a: &mut S, b: &dyn PartialReflect) -> Result<(), ApplyError> { +pub fn set_try_apply( + a: &mut S, + b: &(dyn PartialReflect + Send + Sync), +) -> Result<(), ApplyError> { let set_value = b.reflect_ref().as_set()?; for b_value in set_value.iter() { diff --git a/crates/bevy_reflect/src/std_traits.rs b/crates/bevy_reflect/src/std_traits.rs index cad001132bd25..4379f01c640ab 100644 --- a/crates/bevy_reflect/src/std_traits.rs +++ b/crates/bevy_reflect/src/std_traits.rs @@ -6,16 +6,16 @@ use alloc::boxed::Box; /// A [`ReflectDefault`] for type `T` can be obtained via [`FromType::from_type`]. #[derive(Clone)] pub struct ReflectDefault { - default: fn() -> Box, + default: fn() -> Box, } impl ReflectDefault { - pub fn default(&self) -> Box { + pub fn default(&self) -> Box { (self.default)() } } -impl FromType for ReflectDefault { +impl FromType for ReflectDefault { fn from_type() -> Self { ReflectDefault { default: || Box::::default(), diff --git a/crates/bevy_reflect/src/struct_trait.rs b/crates/bevy_reflect/src/struct_trait.rs index 3f96c74b3cf81..809c95b367020 100644 --- a/crates/bevy_reflect/src/struct_trait.rs +++ b/crates/bevy_reflect/src/struct_trait.rs @@ -38,7 +38,7 @@ use core::{ /// assert_eq!(foo.field_len(), 1); /// assert_eq!(foo.name_at(0), Some("bar")); /// -/// let field: &dyn PartialReflect = foo.field("bar").unwrap(); +/// let field: &(dyn PartialReflect + Send + Sync) = foo.field("bar").unwrap(); /// assert_eq!(field.try_downcast_ref::(), Some(&123)); /// ``` /// @@ -48,19 +48,19 @@ use core::{ pub trait Struct: PartialReflect { /// Returns a reference to the value of the field named `name` as a `&dyn /// PartialReflect`. - fn field(&self, name: &str) -> Option<&dyn PartialReflect>; + fn field(&self, name: &str) -> Option<&(dyn PartialReflect + Send + Sync)>; /// Returns a mutable reference to the value of the field named `name` as a - /// `&mut dyn PartialReflect`. - fn field_mut(&mut self, name: &str) -> Option<&mut dyn PartialReflect>; + /// `&mut (dyn PartialReflect + Send + Sync)`. + fn field_mut(&mut self, name: &str) -> Option<&mut (dyn PartialReflect + Send + Sync)>; /// Returns a reference to the value of the field with index `index` as a - /// `&dyn PartialReflect`. - fn field_at(&self, index: usize) -> Option<&dyn PartialReflect>; + /// `&(dyn PartialReflect + Send + Sync)`. + fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)>; /// Returns a mutable reference to the value of the field with index `index` - /// as a `&mut dyn PartialReflect`. - fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>; + /// as a `&mut (dyn PartialReflect + Send + Sync)`. + fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)>; /// Returns the name of the field with index `index`. fn name_at(&self, index: usize) -> Option<&str>; @@ -111,7 +111,7 @@ impl StructInfo { /// # Arguments /// /// * `fields`: The fields of this struct in the order they are defined - pub fn new(fields: &[NamedField]) -> Self { + pub fn new(fields: &[NamedField]) -> Self { let field_indices = fields .iter() .enumerate() @@ -207,7 +207,7 @@ impl<'a> FieldIter<'a> { } impl<'a> Iterator for FieldIter<'a> { - type Item = &'a dyn PartialReflect; + type Item = &'a (dyn PartialReflect + Send + Sync); fn next(&mut self) -> Option { let value = self.struct_val.field_at(self.index); @@ -246,32 +246,41 @@ impl<'a> ExactSizeIterator for FieldIter<'a> {} pub trait GetField { /// Returns a reference to the value of the field named `name`, downcast to /// `T`. - fn get_field(&self, name: &str) -> Option<&T>; + fn get_field(&self, name: &str) -> Option<&T>; /// Returns a mutable reference to the value of the field named `name`, /// downcast to `T`. - fn get_field_mut(&mut self, name: &str) -> Option<&mut T>; + fn get_field_mut( + &mut self, + name: &str, + ) -> Option<&mut T>; } impl GetField for S { - fn get_field(&self, name: &str) -> Option<&T> { + fn get_field(&self, name: &str) -> Option<&T> { self.field(name) .and_then(|value| value.try_downcast_ref::()) } - fn get_field_mut(&mut self, name: &str) -> Option<&mut T> { + fn get_field_mut( + &mut self, + name: &str, + ) -> Option<&mut T> { self.field_mut(name) .and_then(|value| value.try_downcast_mut::()) } } impl GetField for dyn Struct { - fn get_field(&self, name: &str) -> Option<&T> { + fn get_field(&self, name: &str) -> Option<&T> { self.field(name) .and_then(|value| value.try_downcast_ref::()) } - fn get_field_mut(&mut self, name: &str) -> Option<&mut T> { + fn get_field_mut( + &mut self, + name: &str, + ) -> Option<&mut T> { self.field_mut(name) .and_then(|value| value.try_downcast_mut::()) } @@ -281,7 +290,7 @@ impl GetField for dyn Struct { #[derive(Default)] pub struct DynamicStruct { represented_type: Option<&'static TypeInfo>, - fields: Vec>, + fields: Vec>, field_names: Vec>, field_indices: HashMap, usize>, } @@ -312,7 +321,7 @@ impl DynamicStruct { pub fn insert_boxed<'a>( &mut self, name: impl Into>, - value: Box, + value: Box, ) { let name: Cow = name.into(); if let Some(index) = self.field_indices.get(&name) { @@ -328,7 +337,11 @@ impl DynamicStruct { /// Inserts a field named `name` with the typed value `value` into the struct. /// /// If the field already exists, it is overwritten. - pub fn insert<'a, T: PartialReflect>(&mut self, name: impl Into>, value: T) { + pub fn insert<'a, T: PartialReflect + Send + Sync>( + &mut self, + name: impl Into>, + value: T, + ) { self.insert_boxed(name, Box::new(value)); } @@ -340,14 +353,14 @@ impl DynamicStruct { impl Struct for DynamicStruct { #[inline] - fn field(&self, name: &str) -> Option<&dyn PartialReflect> { + fn field(&self, name: &str) -> Option<&(dyn PartialReflect + Send + Sync)> { self.field_indices .get(name) .map(|index| &*self.fields[*index]) } #[inline] - fn field_mut(&mut self, name: &str) -> Option<&mut dyn PartialReflect> { + fn field_mut(&mut self, name: &str) -> Option<&mut (dyn PartialReflect + Send + Sync)> { if let Some(index) = self.field_indices.get(name) { Some(&mut *self.fields[*index]) } else { @@ -356,12 +369,12 @@ impl Struct for DynamicStruct { } #[inline] - fn field_at(&self, index: usize) -> Option<&dyn PartialReflect> { + fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)> { self.fields.get(index).map(|value| &**value) } #[inline] - fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect> { + fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)> { self.fields.get_mut(index).map(|value| &mut **value) } @@ -391,31 +404,33 @@ impl PartialReflect for DynamicStruct { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } #[inline] - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } #[inline] - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Err(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { None } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { None } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { let struct_value = value.reflect_ref().as_struct()?; for (i, value) in struct_value.iter_fields().enumerate() { @@ -448,7 +463,7 @@ impl PartialReflect for DynamicStruct { ReflectOwned::Struct(self) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { struct_partial_eq(self, value) } @@ -472,13 +487,15 @@ impl Debug for DynamicStruct { } } -impl<'a, N> FromIterator<(N, Box)> for DynamicStruct +impl<'a, N> FromIterator<(N, Box)> for DynamicStruct where N: Into>, { /// Create a dynamic struct that doesn't represent a type from the /// field name, field value pairs. - fn from_iter)>>(fields: I) -> Self { + fn from_iter)>>( + fields: I, + ) -> Self { let mut dynamic_struct = Self::default(); for (name, value) in fields.into_iter() { dynamic_struct.insert_boxed(name, value); @@ -488,7 +505,7 @@ where } impl IntoIterator for DynamicStruct { - type Item = Box; + type Item = Box; type IntoIter = alloc::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { @@ -497,7 +514,7 @@ impl IntoIterator for DynamicStruct { } impl<'a> IntoIterator for &'a DynamicStruct { - type Item = &'a dyn PartialReflect; + type Item = &'a (dyn PartialReflect + Send + Sync); type IntoIter = FieldIter<'a>; fn into_iter(self) -> Self::IntoIter { @@ -515,7 +532,10 @@ impl<'a> IntoIterator for &'a DynamicStruct { /// /// Returns [`None`] if the comparison couldn't even be performed. #[inline] -pub fn struct_partial_eq(a: &S, b: &dyn PartialReflect) -> Option { +pub fn struct_partial_eq( + a: &S, + b: &(dyn PartialReflect + Send + Sync), +) -> Option { let ReflectRef::Struct(struct_value) = b.reflect_ref() else { return Some(false); }; @@ -549,7 +569,7 @@ pub fn struct_partial_eq(a: &S, b: &dyn PartialReflect) -> O /// foo: usize /// } /// -/// let my_struct: &dyn Reflect = &MyStruct { foo: 123 }; +/// let my_struct: &(dyn Reflect + Send + Sync) = &MyStruct { foo: 123 }; /// println!("{:#?}", my_struct); /// /// // Output: diff --git a/crates/bevy_reflect/src/tuple.rs b/crates/bevy_reflect/src/tuple.rs index 31ad67fdcf937..9f6bf35b1d7d0 100644 --- a/crates/bevy_reflect/src/tuple.rs +++ b/crates/bevy_reflect/src/tuple.rs @@ -31,7 +31,7 @@ use core::{ /// let foo = (123_u32, true); /// assert_eq!(foo.field_len(), 2); /// -/// let field: &dyn PartialReflect = foo.field(0).unwrap(); +/// let field: &(dyn PartialReflect + Send + Sync) = foo.field(0).unwrap(); /// assert_eq!(field.try_downcast_ref::(), Some(&123)); /// ``` /// @@ -39,12 +39,12 @@ use core::{ /// [reflection]: crate pub trait Tuple: PartialReflect { /// Returns a reference to the value of the field with index `index` as a - /// `&dyn Reflect`. - fn field(&self, index: usize) -> Option<&dyn PartialReflect>; + /// `&(dyn Reflect + Send + Sync)`. + fn field(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)>; /// Returns a mutable reference to the value of the field with index `index` - /// as a `&mut dyn Reflect`. - fn field_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>; + /// as a `&mut (dyn Reflect + Send + Sync)`. + fn field_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)>; /// Returns the number of fields in the tuple. fn field_len(&self) -> usize; @@ -53,7 +53,7 @@ pub trait Tuple: PartialReflect { fn iter_fields(&self) -> TupleFieldIter; /// Drain the fields of this tuple to get a vector of owned values. - fn drain(self: Box) -> Vec>; + fn drain(self: Box) -> Vec>; /// Clones the tuple into a [`DynamicTuple`]. #[deprecated(since = "0.16.0", note = "use `to_dynamic_tuple` instead")] @@ -91,7 +91,7 @@ impl<'a> TupleFieldIter<'a> { } impl<'a> Iterator for TupleFieldIter<'a> { - type Item = &'a dyn PartialReflect; + type Item = &'a (dyn PartialReflect + Send + Sync); fn next(&mut self) -> Option { let value = self.tuple.field(self.index); @@ -125,32 +125,41 @@ impl<'a> ExactSizeIterator for TupleFieldIter<'a> {} pub trait GetTupleField { /// Returns a reference to the value of the field with index `index`, /// downcast to `T`. - fn get_field(&self, index: usize) -> Option<&T>; + fn get_field(&self, index: usize) -> Option<&T>; /// Returns a mutable reference to the value of the field with index /// `index`, downcast to `T`. - fn get_field_mut(&mut self, index: usize) -> Option<&mut T>; + fn get_field_mut( + &mut self, + index: usize, + ) -> Option<&mut T>; } impl GetTupleField for S { - fn get_field(&self, index: usize) -> Option<&T> { + fn get_field(&self, index: usize) -> Option<&T> { self.field(index) .and_then(|value| value.try_downcast_ref::()) } - fn get_field_mut(&mut self, index: usize) -> Option<&mut T> { + fn get_field_mut( + &mut self, + index: usize, + ) -> Option<&mut T> { self.field_mut(index) .and_then(|value| value.try_downcast_mut::()) } } impl GetTupleField for dyn Tuple { - fn get_field(&self, index: usize) -> Option<&T> { + fn get_field(&self, index: usize) -> Option<&T> { self.field(index) .and_then(|value| value.try_downcast_ref::()) } - fn get_field_mut(&mut self, index: usize) -> Option<&mut T> { + fn get_field_mut( + &mut self, + index: usize, + ) -> Option<&mut T> { self.field_mut(index) .and_then(|value| value.try_downcast_mut::()) } @@ -172,7 +181,7 @@ impl TupleInfo { /// # Arguments /// /// * `fields`: The fields of this tuple in the order they are defined - pub fn new(fields: &[UnnamedField]) -> Self { + pub fn new(fields: &[UnnamedField]) -> Self { Self { ty: Type::of::(), generics: Generics::new(), @@ -218,7 +227,7 @@ impl TupleInfo { #[derive(Default, Debug)] pub struct DynamicTuple { represented_type: Option<&'static TypeInfo>, - fields: Vec>, + fields: Vec>, } impl DynamicTuple { @@ -241,13 +250,13 @@ impl DynamicTuple { } /// Appends an element with value `value` to the tuple. - pub fn insert_boxed(&mut self, value: Box) { + pub fn insert_boxed(&mut self, value: Box) { self.represented_type = None; self.fields.push(value); } /// Appends a typed element with value `value` to the tuple. - pub fn insert(&mut self, value: T) { + pub fn insert(&mut self, value: T) { self.represented_type = None; self.insert_boxed(Box::new(value)); } @@ -255,12 +264,12 @@ impl DynamicTuple { impl Tuple for DynamicTuple { #[inline] - fn field(&self, index: usize) -> Option<&dyn PartialReflect> { + fn field(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)> { self.fields.get(index).map(|field| &**field) } #[inline] - fn field_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect> { + fn field_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)> { self.fields.get_mut(index).map(|field| &mut **field) } @@ -278,7 +287,7 @@ impl Tuple for DynamicTuple { } #[inline] - fn drain(self: Box) -> Vec> { + fn drain(self: Box) -> Vec> { self.fields } } @@ -290,31 +299,33 @@ impl PartialReflect for DynamicTuple { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Err(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { None } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { None } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { tuple_apply(self, value); } @@ -338,11 +349,11 @@ impl PartialReflect for DynamicTuple { ReflectOwned::Tuple(self) } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { tuple_try_apply(self, value) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { tuple_partial_eq(self, value) } @@ -360,8 +371,8 @@ impl PartialReflect for DynamicTuple { impl_type_path!((in bevy_reflect) DynamicTuple); -impl FromIterator> for DynamicTuple { - fn from_iter>>(fields: I) -> Self { +impl FromIterator> for DynamicTuple { + fn from_iter>>(fields: I) -> Self { Self { represented_type: None, fields: fields.into_iter().collect(), @@ -370,7 +381,7 @@ impl FromIterator> for DynamicTuple { } impl IntoIterator for DynamicTuple { - type Item = Box; + type Item = Box; type IntoIter = vec::IntoIter; fn into_iter(self) -> Self::IntoIter { @@ -379,7 +390,7 @@ impl IntoIterator for DynamicTuple { } impl<'a> IntoIterator for &'a DynamicTuple { - type Item = &'a dyn PartialReflect; + type Item = &'a (dyn PartialReflect + Send + Sync); type IntoIter = TupleFieldIter<'a>; fn into_iter(self) -> Self::IntoIter { @@ -393,7 +404,7 @@ impl<'a> IntoIterator for &'a DynamicTuple { /// /// This function panics if `b` is not a tuple. #[inline] -pub fn tuple_apply(a: &mut T, b: &dyn PartialReflect) { +pub fn tuple_apply(a: &mut T, b: &(dyn PartialReflect + Send + Sync)) { if let Err(err) = tuple_try_apply(a, b) { panic!("{err}"); } @@ -407,7 +418,10 @@ pub fn tuple_apply(a: &mut T, b: &dyn PartialReflect) { /// This function returns an [`ApplyError::MismatchedKinds`] if `b` is not a tuple or if /// applying elements to each other fails. #[inline] -pub fn tuple_try_apply(a: &mut T, b: &dyn PartialReflect) -> Result<(), ApplyError> { +pub fn tuple_try_apply( + a: &mut T, + b: &(dyn PartialReflect + Send + Sync), +) -> Result<(), ApplyError> { let tuple = b.reflect_ref().as_tuple()?; for (i, value) in tuple.iter_fields().enumerate() { @@ -428,7 +442,10 @@ pub fn tuple_try_apply(a: &mut T, b: &dyn PartialReflect) -> Result<() /// /// Returns [`None`] if the comparison couldn't even be performed. #[inline] -pub fn tuple_partial_eq(a: &T, b: &dyn PartialReflect) -> Option { +pub fn tuple_partial_eq( + a: &T, + b: &(dyn PartialReflect + Send + Sync), +) -> Option { let ReflectRef::Tuple(b) = b.reflect_ref() else { return Some(false); }; @@ -453,7 +470,7 @@ pub fn tuple_partial_eq(a: &T, b: &dyn PartialReflect) -> Opt /// ``` /// use bevy_reflect::Reflect; /// -/// let my_tuple: &dyn Reflect = &(1, 2, 3); +/// let my_tuple: &(dyn Reflect + Send + Sync) = &(1, 2, 3); /// println!("{:#?}", my_tuple); /// /// // Output: @@ -475,19 +492,19 @@ pub fn tuple_debug(dyn_tuple: &dyn Tuple, f: &mut Formatter<'_>) -> core::fmt::R macro_rules! impl_reflect_tuple { {$($index:tt : $name:tt),*} => { - impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> Tuple for ($($name,)*) { + impl<$($name: Reflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration),*> Tuple for ($($name,)*) { #[inline] - fn field(&self, index: usize) -> Option<&dyn PartialReflect> { + fn field(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)> { match index { - $($index => Some(&self.$index as &dyn PartialReflect),)* + $($index => Some(&self.$index as &(dyn PartialReflect + Send + Sync)),)* _ => None, } } #[inline] - fn field_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect> { + fn field_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)> { match index { - $($index => Some(&mut self.$index as &mut dyn PartialReflect),)* + $($index => Some(&mut self.$index as &mut (dyn PartialReflect + Send + Sync)),)* _ => None, } } @@ -507,40 +524,40 @@ macro_rules! impl_reflect_tuple { } #[inline] - fn drain(self: Box) -> Vec> { + fn drain(self: Box) -> Vec> { vec![ $(Box::new(self.$index),)* ] } } - impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> PartialReflect for ($($name,)*) { + impl<$($name: Reflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration),*> PartialReflect for ($($name,)*) { fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { Some(::type_info()) } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect(self: Box) -> Result, Box> { Ok(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { Some(self) } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { Some(self) } @@ -560,19 +577,19 @@ macro_rules! impl_reflect_tuple { ReflectOwned::Tuple(self) } - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { crate::tuple_partial_eq(self, value) } - fn apply(&mut self, value: &dyn PartialReflect) { + fn apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) { crate::tuple_apply(self, value); } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { crate::tuple_try_apply(self, value) } - fn reflect_clone(&self) -> Result, ReflectCloneError> { + fn reflect_clone(&self) -> Result, ReflectCloneError> { Ok(Box::new(( $( self.$index.reflect_clone()? @@ -583,7 +600,7 @@ macro_rules! impl_reflect_tuple { } } - impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> Reflect for ($($name,)*) { + impl<$($name: Reflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration),*> Reflect for ($($name,)*) { fn into_any(self: Box) -> Box { self } @@ -596,25 +613,25 @@ macro_rules! impl_reflect_tuple { self } - fn into_reflect(self: Box) -> Box { + fn into_reflect(self: Box) -> Box { self } - fn as_reflect(&self) -> &dyn Reflect { + fn as_reflect(&self) -> &(dyn Reflect + Send + Sync) { self } - fn as_reflect_mut(&mut self) -> &mut dyn Reflect { + fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + Send + Sync) { self } - fn set(&mut self, value: Box) -> Result<(), Box> { + fn set(&mut self, value: Box) -> Result<(), Box> { *self = value.take()?; Ok(()) } } - impl <$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> Typed for ($($name,)*) { + impl <$($name: Reflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration),*> Typed for ($($name,)*) { fn type_info() -> &'static TypeInfo { static CELL: $crate::utility::GenericTypeInfoCell = $crate::utility::GenericTypeInfoCell::new(); CELL.get_or_insert::(|| { @@ -627,7 +644,7 @@ macro_rules! impl_reflect_tuple { } } - impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> GetTypeRegistration for ($($name,)*) { + impl<$($name: Reflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration),*> GetTypeRegistration for ($($name,)*) { fn get_type_registration() -> TypeRegistration { TypeRegistration::of::<($($name,)*)>() } @@ -637,9 +654,9 @@ macro_rules! impl_reflect_tuple { } } - impl<$($name: FromReflect + MaybeTyped + TypePath + GetTypeRegistration),*> FromReflect for ($($name,)*) + impl<$($name: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration),*> FromReflect for ($($name,)*) { - fn from_reflect(reflect: &dyn PartialReflect) -> Option { + fn from_reflect(reflect: &(dyn PartialReflect + Send + Sync)) -> Option { let _ref_tuple = reflect.reflect_ref().as_tuple().ok()?; Some( @@ -753,7 +770,7 @@ const _: () = { macro_rules! impl_from_arg_tuple { ($(#[$meta:meta])* $($name: ident),*) => { $(#[$meta])* - $crate::func::args::impl_from_arg!(($($name,)*); <$($name: FromReflect + MaybeTyped + TypePath + GetTypeRegistration),*>); + $crate::func::args::impl_from_arg!(($($name,)*); <$($name: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration),*>); }; } @@ -768,7 +785,7 @@ const _: () = { macro_rules! impl_into_return_tuple { ($(#[$meta:meta])* $($name: ident),+) => { $(#[$meta])* - $crate::func::impl_into_return!(($($name,)*); <$($name: FromReflect + MaybeTyped + TypePath + GetTypeRegistration),*>); + $crate::func::impl_into_return!(($($name,)*); <$($name: FromReflect + Send + Sync + MaybeTyped + TypePath + GetTypeRegistration),*>); }; } diff --git a/crates/bevy_reflect/src/tuple_struct.rs b/crates/bevy_reflect/src/tuple_struct.rs index ed8a0c5ea17ab..f5faba2be8c2e 100644 --- a/crates/bevy_reflect/src/tuple_struct.rs +++ b/crates/bevy_reflect/src/tuple_struct.rs @@ -34,7 +34,7 @@ use core::{ /// /// assert_eq!(foo.field_len(), 1); /// -/// let field: &dyn PartialReflect = foo.field(0).unwrap(); +/// let field: &(dyn PartialReflect + Send + Sync) = foo.field(0).unwrap(); /// assert_eq!(field.try_downcast_ref::(), Some(&123)); /// ``` /// @@ -42,12 +42,12 @@ use core::{ /// [reflection]: crate pub trait TupleStruct: PartialReflect { /// Returns a reference to the value of the field with index `index` as a - /// `&dyn Reflect`. - fn field(&self, index: usize) -> Option<&dyn PartialReflect>; + /// `&(dyn Reflect + Send + Sync)`. + fn field(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)>; /// Returns a mutable reference to the value of the field with index `index` - /// as a `&mut dyn Reflect`. - fn field_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>; + /// as a `&mut (dyn Reflect + Send + Sync)`. + fn field_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)>; /// Returns the number of fields in the tuple struct. fn field_len(&self) -> usize; @@ -92,7 +92,7 @@ impl TupleStructInfo { /// # Arguments /// /// * `fields`: The fields of this struct in the order they are defined - pub fn new(fields: &[UnnamedField]) -> Self { + pub fn new(fields: &[UnnamedField]) -> Self { Self { ty: Type::of::(), generics: Generics::new(), @@ -161,7 +161,7 @@ impl<'a> TupleStructFieldIter<'a> { } impl<'a> Iterator for TupleStructFieldIter<'a> { - type Item = &'a dyn PartialReflect; + type Item = &'a (dyn PartialReflect + Send + Sync); fn next(&mut self) -> Option { let value = self.tuple_struct.field(self.index); @@ -198,32 +198,41 @@ impl<'a> ExactSizeIterator for TupleStructFieldIter<'a> {} pub trait GetTupleStructField { /// Returns a reference to the value of the field with index `index`, /// downcast to `T`. - fn get_field(&self, index: usize) -> Option<&T>; + fn get_field(&self, index: usize) -> Option<&T>; /// Returns a mutable reference to the value of the field with index /// `index`, downcast to `T`. - fn get_field_mut(&mut self, index: usize) -> Option<&mut T>; + fn get_field_mut( + &mut self, + index: usize, + ) -> Option<&mut T>; } impl GetTupleStructField for S { - fn get_field(&self, index: usize) -> Option<&T> { + fn get_field(&self, index: usize) -> Option<&T> { self.field(index) .and_then(|value| value.try_downcast_ref::()) } - fn get_field_mut(&mut self, index: usize) -> Option<&mut T> { + fn get_field_mut( + &mut self, + index: usize, + ) -> Option<&mut T> { self.field_mut(index) .and_then(|value| value.try_downcast_mut::()) } } impl GetTupleStructField for dyn TupleStruct { - fn get_field(&self, index: usize) -> Option<&T> { + fn get_field(&self, index: usize) -> Option<&T> { self.field(index) .and_then(|value| value.try_downcast_ref::()) } - fn get_field_mut(&mut self, index: usize) -> Option<&mut T> { + fn get_field_mut( + &mut self, + index: usize, + ) -> Option<&mut T> { self.field_mut(index) .and_then(|value| value.try_downcast_mut::()) } @@ -233,7 +242,7 @@ impl GetTupleStructField for dyn TupleStruct { #[derive(Default)] pub struct DynamicTupleStruct { represented_type: Option<&'static TypeInfo>, - fields: Vec>, + fields: Vec>, } impl DynamicTupleStruct { @@ -257,24 +266,24 @@ impl DynamicTupleStruct { } /// Appends an element with value `value` to the tuple struct. - pub fn insert_boxed(&mut self, value: Box) { + pub fn insert_boxed(&mut self, value: Box) { self.fields.push(value); } /// Appends a typed element with value `value` to the tuple struct. - pub fn insert(&mut self, value: T) { + pub fn insert(&mut self, value: T) { self.insert_boxed(Box::new(value)); } } impl TupleStruct for DynamicTupleStruct { #[inline] - fn field(&self, index: usize) -> Option<&dyn PartialReflect> { + fn field(&self, index: usize) -> Option<&(dyn PartialReflect + Send + Sync)> { self.fields.get(index).map(|field| &**field) } #[inline] - fn field_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect> { + fn field_mut(&mut self, index: usize) -> Option<&mut (dyn PartialReflect + Send + Sync)> { self.fields.get_mut(index).map(|field| &mut **field) } @@ -299,33 +308,35 @@ impl PartialReflect for DynamicTupleStruct { } #[inline] - fn into_partial_reflect(self: Box) -> Box { + fn into_partial_reflect(self: Box) -> Box { self } #[inline] - fn as_partial_reflect(&self) -> &dyn PartialReflect { + fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { self } #[inline] - fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { + fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { self } - fn try_into_reflect(self: Box) -> Result, Box> { + fn try_into_reflect( + self: Box, + ) -> Result, Box> { Err(self) } - fn try_as_reflect(&self) -> Option<&dyn Reflect> { + fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { None } - fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { + fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { None } - fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { + fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { let tuple_struct = value.reflect_ref().as_tuple_struct()?; for (i, value) in tuple_struct.iter_fields().enumerate() { @@ -358,7 +369,7 @@ impl PartialReflect for DynamicTupleStruct { } #[inline] - fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option { + fn reflect_partial_eq(&self, value: &(dyn PartialReflect + Send + Sync)) -> Option { tuple_struct_partial_eq(self, value) } @@ -391,8 +402,8 @@ impl From for DynamicTupleStruct { } } -impl FromIterator> for DynamicTupleStruct { - fn from_iter>>(fields: I) -> Self { +impl FromIterator> for DynamicTupleStruct { + fn from_iter>>(fields: I) -> Self { Self { represented_type: None, fields: fields.into_iter().collect(), @@ -401,7 +412,7 @@ impl FromIterator> for DynamicTupleStruct { } impl IntoIterator for DynamicTupleStruct { - type Item = Box; + type Item = Box; type IntoIter = alloc::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { @@ -410,7 +421,7 @@ impl IntoIterator for DynamicTupleStruct { } impl<'a> IntoIterator for &'a DynamicTupleStruct { - type Item = &'a dyn PartialReflect; + type Item = &'a (dyn PartialReflect + Send + Sync); type IntoIter = TupleStructFieldIter<'a>; fn into_iter(self) -> Self::IntoIter { @@ -429,7 +440,7 @@ impl<'a> IntoIterator for &'a DynamicTupleStruct { #[inline] pub fn tuple_struct_partial_eq( a: &S, - b: &dyn PartialReflect, + b: &(dyn PartialReflect + Send + Sync), ) -> Option { let ReflectRef::TupleStruct(tuple_struct) = b.reflect_ref() else { return Some(false); @@ -461,7 +472,7 @@ pub fn tuple_struct_partial_eq( /// #[derive(Reflect)] /// struct MyTupleStruct(usize); /// -/// let my_tuple_struct: &dyn Reflect = &MyTupleStruct(123); +/// let my_tuple_struct: &(dyn Reflect + Send + Sync) = &MyTupleStruct(123); /// println!("{:#?}", my_tuple_struct); /// /// // Output: diff --git a/crates/bevy_reflect/src/type_info.rs b/crates/bevy_reflect/src/type_info.rs index 1a3be15c36126..f70dcb5853d8c 100644 --- a/crates/bevy_reflect/src/type_info.rs +++ b/crates/bevy_reflect/src/type_info.rs @@ -62,13 +62,13 @@ use thiserror::Error; /// # } /// # impl PartialReflect for MyStruct { /// # fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { todo!() } -/// # fn into_partial_reflect(self: Box) -> Box { todo!() } -/// # fn as_partial_reflect(&self) -> &dyn PartialReflect { todo!() } -/// # fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { todo!() } -/// # fn try_into_reflect(self: Box) -> Result, Box> { todo!() } -/// # fn try_as_reflect(&self) -> Option<&dyn Reflect> { todo!() } -/// # fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { todo!() } -/// # fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { todo!() } +/// # fn into_partial_reflect(self: Box) -> Box { todo!() } +/// # fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { todo!() } +/// # fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { todo!() } +/// # fn try_into_reflect(self: Box) -> Result, Box> { todo!() } +/// # fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { todo!() } +/// # fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { todo!() } +/// # fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { todo!() } /// # fn reflect_ref(&self) -> ReflectRef { todo!() } /// # fn reflect_mut(&mut self) -> ReflectMut { todo!() } /// # fn reflect_owned(self: Box) -> ReflectOwned { todo!() } @@ -77,10 +77,10 @@ use thiserror::Error; /// # fn into_any(self: Box) -> Box { todo!() } /// # fn as_any(&self) -> &dyn Any { todo!() } /// # fn as_any_mut(&mut self) -> &mut dyn Any { todo!() } -/// # fn into_reflect(self: Box) -> Box { todo!() } -/// # fn as_reflect(&self) -> &dyn Reflect { todo!() } -/// # fn as_reflect_mut(&mut self) -> &mut dyn Reflect { todo!() } -/// # fn set(&mut self, value: Box) -> Result<(), Box> { todo!() } +/// # fn into_reflect(self: Box) -> Box { todo!() } +/// # fn as_reflect(&self) -> &(dyn Reflect + Send + Sync) { todo!() } +/// # fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + Send + Sync) { todo!() } +/// # fn set(&mut self, value: Box) -> Result<(), Box> { todo!() } /// # } /// ``` /// @@ -120,7 +120,7 @@ pub trait MaybeTyped: PartialReflect { } } -impl MaybeTyped for T { +impl MaybeTyped for T { fn maybe_type_info() -> Option<&'static TypeInfo> { Some(T::type_info()) } @@ -557,7 +557,7 @@ pub struct OpaqueInfo { } impl OpaqueInfo { - pub fn new() -> Self { + pub fn new() -> Self { Self { ty: Type::of::(), generics: Generics::new(), diff --git a/crates/bevy_reflect/src/type_path.rs b/crates/bevy_reflect/src/type_path.rs index 3acc9bc94a4a0..4cb0fb3891bec 100644 --- a/crates/bevy_reflect/src/type_path.rs +++ b/crates/bevy_reflect/src/type_path.rs @@ -154,7 +154,7 @@ pub trait DynamicTypePath { fn reflect_module_path(&self) -> Option<&str>; } -impl DynamicTypePath for T { +impl DynamicTypePath for T { #[inline] fn reflect_type_path(&self) -> &str { Self::type_path() diff --git a/crates/bevy_reflect/src/type_registry.rs b/crates/bevy_reflect/src/type_registry.rs index cf80749edebbb..e839f2bba8927 100644 --- a/crates/bevy_reflect/src/type_registry.rs +++ b/crates/bevy_reflect/src/type_registry.rs @@ -302,7 +302,9 @@ impl TypeRegistry { /// type_registry.register_type_data::, ReflectSerialize>(); /// type_registry.register_type_data::, ReflectDeserialize>(); /// ``` - pub fn register_type_data>(&mut self) { + pub fn register_type_data>( + &mut self, + ) { let data = self.get_mut(TypeId::of::()).unwrap_or_else(|| { panic!( "attempted to call `TypeRegistry::register_type_data` for type `{T}` with data `{D}` without registering `{T}` first", @@ -520,7 +522,7 @@ impl Debug for TypeRegistration { impl TypeRegistration { /// Creates type registration information for `T`. - pub fn of() -> Self { + pub fn of() -> Self { Self { data: Default::default(), type_info: T::type_info(), @@ -711,10 +713,12 @@ pub trait FromType { /// [`FromType::from_type`]. #[derive(Clone)] pub struct ReflectSerialize { - get_serializable: fn(value: &dyn Reflect) -> Serializable, + get_serializable: fn(value: &(dyn Reflect + Send + Sync)) -> Serializable, } -impl FromType for ReflectSerialize { +impl FromType + for ReflectSerialize +{ fn from_type() -> Self { ReflectSerialize { get_serializable: |value| { @@ -735,7 +739,7 @@ impl FromType for Reflec impl ReflectSerialize { /// Turn the value into a serializable representation - pub fn get_serializable<'a>(&self, value: &'a dyn Reflect) -> Serializable<'a> { + pub fn get_serializable<'a>(&self, value: &'a (dyn Reflect + Send + Sync)) -> Serializable<'a> { (self.get_serializable)(value) } } @@ -748,7 +752,7 @@ impl ReflectSerialize { pub struct ReflectDeserialize { pub func: fn( deserializer: &mut dyn erased_serde::Deserializer, - ) -> Result, erased_serde::Error>, + ) -> Result, erased_serde::Error>, } impl ReflectDeserialize { @@ -757,7 +761,10 @@ impl ReflectDeserialize { /// The underlying type of the reflected value, and thus the expected /// structure of the serialized data, is determined by the type used to /// construct this `ReflectDeserialize` value. - pub fn deserialize<'de, D>(&self, deserializer: D) -> Result, D::Error> + pub fn deserialize<'de, D>( + &self, + deserializer: D, + ) -> Result, D::Error> where D: serde::Deserializer<'de>, { @@ -767,7 +774,7 @@ impl ReflectDeserialize { } } -impl Deserialize<'a> + Reflect> FromType for ReflectDeserialize { +impl Deserialize<'a> + Reflect + Send + Sync> FromType for ReflectDeserialize { fn from_type() -> Self { ReflectDeserialize { func: |deserializer| Ok(Box::new(T::deserialize(deserializer)?)), @@ -777,7 +784,7 @@ impl Deserialize<'a> + Reflect> FromType for ReflectDeserialize { /// [`Reflect`] values are commonly used in situations where the actual types of values /// are not known at runtime. In such situations you might have access to a `*const ()` pointer -/// that you know implements [`Reflect`], but have no way of turning it into a `&dyn Reflect`. +/// that you know implements [`Reflect`], but have no way of turning it into a `&(dyn Reflect + Send + Sync)`. /// /// This is where [`ReflectFromPtr`] comes in, when creating a [`ReflectFromPtr`] for a given type `T: Reflect`. /// Internally, this saves a concrete function `*const T -> const dyn Reflect` which lets you create a trait object of [`Reflect`] @@ -808,8 +815,8 @@ impl Deserialize<'a> + Reflect> FromType for ReflectDeserialize { #[derive(Clone)] pub struct ReflectFromPtr { type_id: TypeId, - from_ptr: unsafe fn(Ptr) -> &dyn Reflect, - from_ptr_mut: unsafe fn(PtrMut) -> &mut dyn Reflect, + from_ptr: unsafe fn(Ptr) -> &(dyn Reflect + Send + Sync), + from_ptr_mut: unsafe fn(PtrMut) -> &mut (dyn Reflect + Send + Sync), } #[expect( @@ -822,28 +829,31 @@ impl ReflectFromPtr { self.type_id } - /// Convert `Ptr` into `&dyn Reflect`. + /// Convert `Ptr` into `&(dyn Reflect + Send + Sync)`. /// /// # Safety /// /// `val` must be a pointer to value of the type that the [`ReflectFromPtr`] was constructed for. /// This can be verified by checking that the type id returned by [`ReflectFromPtr::type_id`] is the expected one. - pub unsafe fn as_reflect<'a>(&self, val: Ptr<'a>) -> &'a dyn Reflect { + pub unsafe fn as_reflect<'a>(&self, val: Ptr<'a>) -> &'a (dyn Reflect + Send + Sync) { // SAFETY: contract uphold by the caller. unsafe { (self.from_ptr)(val) } } - /// Convert `PtrMut` into `&mut dyn Reflect`. + /// Convert `PtrMut` into `&mut (dyn Reflect + Send + Sync)`. /// /// # Safety /// /// `val` must be a pointer to a value of the type that the [`ReflectFromPtr`] was constructed for /// This can be verified by checking that the type id returned by [`ReflectFromPtr::type_id`] is the expected one. - pub unsafe fn as_reflect_mut<'a>(&self, val: PtrMut<'a>) -> &'a mut dyn Reflect { + pub unsafe fn as_reflect_mut<'a>( + &self, + val: PtrMut<'a>, + ) -> &'a mut (dyn Reflect + Send + Sync) { // SAFETY: contract uphold by the caller. unsafe { (self.from_ptr_mut)(val) } } - /// Get a function pointer to turn a `Ptr` into `&dyn Reflect` for + /// Get a function pointer to turn a `Ptr` into `&(dyn Reflect + Send + Sync)` for /// the type this [`ReflectFromPtr`] was constructed for. /// /// # Safety @@ -851,10 +861,10 @@ impl ReflectFromPtr { /// When calling the unsafe function returned by this method you must ensure that: /// - The input `Ptr` points to the `Reflect` type this `ReflectFromPtr` /// was constructed for. - pub fn from_ptr(&self) -> unsafe fn(Ptr) -> &dyn Reflect { + pub fn from_ptr(&self) -> unsafe fn(Ptr) -> &(dyn Reflect + Send + Sync) { self.from_ptr } - /// Get a function pointer to turn a `PtrMut` into `&mut dyn Reflect` for + /// Get a function pointer to turn a `PtrMut` into `&mut (dyn Reflect + Send + Sync)` for /// the type this [`ReflectFromPtr`] was constructed for. /// /// # Safety @@ -862,7 +872,7 @@ impl ReflectFromPtr { /// When calling the unsafe function returned by this method you must ensure that: /// - The input `PtrMut` points to the `Reflect` type this `ReflectFromPtr` /// was constructed for. - pub fn from_ptr_mut(&self) -> unsafe fn(PtrMut) -> &mut dyn Reflect { + pub fn from_ptr_mut(&self) -> unsafe fn(PtrMut) -> &mut (dyn Reflect + Send + Sync) { self.from_ptr_mut } } @@ -871,7 +881,7 @@ impl ReflectFromPtr { unsafe_code, reason = "We must interact with pointers here, which are inherently unsafe." )] -impl FromType for ReflectFromPtr { +impl FromType for ReflectFromPtr { fn from_type() -> Self { ReflectFromPtr { type_id: TypeId::of::(), @@ -879,11 +889,11 @@ impl FromType for ReflectFromPtr { // SAFETY: `from_ptr_mut` is either called in `ReflectFromPtr::as_reflect` // or returned by `ReflectFromPtr::from_ptr`, both lay out the invariants // required by `deref` - unsafe { ptr.deref::() as &dyn Reflect } + unsafe { ptr.deref::() as &(dyn Reflect + Send + Sync) } }, from_ptr_mut: |ptr| { // SAFETY: same as above, but for `as_reflect_mut`, `from_ptr_mut` and `deref_mut`. - unsafe { ptr.deref_mut::() as &mut dyn Reflect } + unsafe { ptr.deref_mut::() as &mut (dyn Reflect + Send + Sync) } }, } } diff --git a/crates/bevy_reflect/src/utility.rs b/crates/bevy_reflect/src/utility.rs index 33725a4633256..a5635569e403d 100644 --- a/crates/bevy_reflect/src/utility.rs +++ b/crates/bevy_reflect/src/utility.rs @@ -78,13 +78,13 @@ mod sealed { /// # } /// # impl PartialReflect for Foo { /// # fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { todo!() } -/// # fn into_partial_reflect(self: Box) -> Box { todo!() } -/// # fn as_partial_reflect(&self) -> &dyn PartialReflect { todo!() } -/// # fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { todo!() } -/// # fn try_into_reflect(self: Box) -> Result, Box> { todo!() } -/// # fn try_as_reflect(&self) -> Option<&dyn Reflect> { todo!() } -/// # fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { todo!() } -/// # fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { todo!() } +/// # fn into_partial_reflect(self: Box) -> Box { todo!() } +/// # fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { todo!() } +/// # fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { todo!() } +/// # fn try_into_reflect(self: Box) -> Result, Box> { todo!() } +/// # fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { todo!() } +/// # fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { todo!() } +/// # fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { todo!() } /// # fn reflect_ref(&self) -> ReflectRef { todo!() } /// # fn reflect_mut(&mut self) -> ReflectMut { todo!() } /// # fn reflect_owned(self: Box) -> ReflectOwned { todo!() } @@ -93,10 +93,10 @@ mod sealed { /// # fn into_any(self: Box) -> Box { todo!() } /// # fn as_any(&self) -> &dyn Any { todo!() } /// # fn as_any_mut(&mut self) -> &mut dyn Any { todo!() } -/// # fn into_reflect(self: Box) -> Box { todo!() } -/// # fn as_reflect(&self) -> &dyn Reflect { todo!() } -/// # fn as_reflect_mut(&mut self) -> &mut dyn Reflect { todo!() } -/// # fn set(&mut self, value: Box) -> Result<(), Box> { todo!() } +/// # fn into_reflect(self: Box) -> Box { todo!() } +/// # fn as_reflect(&self) -> &(dyn Reflect + Send + Sync) { todo!() } +/// # fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + Send + Sync) { todo!() } +/// # fn set(&mut self, value: Box) -> Result<(), Box> { todo!() } /// # } /// ``` /// @@ -106,7 +106,7 @@ pub struct NonGenericTypeCell(OnceLock); /// See [`NonGenericTypeCell`]. pub type NonGenericTypeInfoCell = NonGenericTypeCell; -impl NonGenericTypeCell { +impl NonGenericTypeCell { /// Initialize a [`NonGenericTypeCell`] for non-generic types. pub const fn new() -> Self { Self(OnceLock::new()) @@ -123,7 +123,7 @@ impl NonGenericTypeCell { } } -impl Default for NonGenericTypeCell { +impl Default for NonGenericTypeCell { fn default() -> Self { Self::new() } @@ -148,7 +148,7 @@ impl Default for NonGenericTypeCell { /// /// struct Foo(T); /// -/// impl Typed for Foo { +/// impl Typed for Foo { /// fn type_info() -> &'static TypeInfo { /// static CELL: GenericTypeInfoCell = GenericTypeInfoCell::new(); /// CELL.get_or_insert::(|| { @@ -163,27 +163,27 @@ impl Default for NonGenericTypeCell { /// # fn type_path() -> &'static str { todo!() } /// # fn short_type_path() -> &'static str { todo!() } /// # } -/// # impl PartialReflect for Foo { +/// # impl PartialReflect for Foo { /// # fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { todo!() } -/// # fn into_partial_reflect(self: Box) -> Box { todo!() } -/// # fn as_partial_reflect(&self) -> &dyn PartialReflect { todo!() } -/// # fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect { todo!() } -/// # fn try_into_reflect(self: Box) -> Result, Box> { todo!() } -/// # fn try_as_reflect(&self) -> Option<&dyn Reflect> { todo!() } -/// # fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> { todo!() } -/// # fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> { todo!() } +/// # fn into_partial_reflect(self: Box) -> Box { todo!() } +/// # fn as_partial_reflect(&self) -> &(dyn PartialReflect + Send + Sync) { todo!() } +/// # fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + Send + Sync) { todo!() } +/// # fn try_into_reflect(self: Box) -> Result, Box> { todo!() } +/// # fn try_as_reflect(&self) -> Option<&(dyn Reflect + Send + Sync)> { todo!() } +/// # fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + Send + Sync)> { todo!() } +/// # fn try_apply(&mut self, value: &(dyn PartialReflect + Send + Sync)) -> Result<(), ApplyError> { todo!() } /// # fn reflect_ref(&self) -> ReflectRef { todo!() } /// # fn reflect_mut(&mut self) -> ReflectMut { todo!() } /// # fn reflect_owned(self: Box) -> ReflectOwned { todo!() } /// # } -/// # impl Reflect for Foo { +/// # impl Reflect for Foo { /// # fn into_any(self: Box) -> Box { todo!() } /// # fn as_any(&self) -> &dyn Any { todo!() } /// # fn as_any_mut(&mut self) -> &mut dyn Any { todo!() } -/// # fn into_reflect(self: Box) -> Box { todo!() } -/// # fn as_reflect(&self) -> &dyn Reflect { todo!() } -/// # fn as_reflect_mut(&mut self) -> &mut dyn Reflect { todo!() } -/// # fn set(&mut self, value: Box) -> Result<(), Box> { todo!() } +/// # fn into_reflect(self: Box) -> Box { todo!() } +/// # fn as_reflect(&self) -> &(dyn Reflect + Send + Sync) { todo!() } +/// # fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + Send + Sync) { todo!() } +/// # fn set(&mut self, value: Box) -> Result<(), Box> { todo!() } /// # } /// ``` /// @@ -201,7 +201,7 @@ impl Default for NonGenericTypeCell { /// static CELL: GenericTypePathCell = GenericTypePathCell::new(); /// CELL.get_or_insert::(|| format!("my_crate::foo::Foo<{}>", T::type_path())) /// } -/// +/// /// fn short_type_path() -> &'static str { /// static CELL: GenericTypePathCell = GenericTypePathCell::new(); /// CELL.get_or_insert::(|| format!("Foo<{}>", T::short_type_path())) diff --git a/crates/bevy_remote/src/builtin_methods.rs b/crates/bevy_remote/src/builtin_methods.rs index e8b6856623cff..b032b9fa0e28a 100644 --- a/crates/bevy_remote/src/builtin_methods.rs +++ b/crates/bevy_remote/src/builtin_methods.rs @@ -948,9 +948,10 @@ pub fn process_remote_mutate_component_request( // Get the reflected representation of the value to be inserted // into the component. - let value: Box = TypedReflectDeserializer::new(value_type, &type_registry) - .deserialize(&value) - .map_err(BrpError::component_error)?; + let value: Box = + TypedReflectDeserializer::new(value_type, &type_registry) + .deserialize(&value) + .map_err(BrpError::component_error)?; // Apply the mutation. reflected @@ -998,7 +999,7 @@ pub fn process_remote_mutate_resource_request( })?; // Use the field's type registration to deserialize the given value. - let deserialized_value: Box = + let deserialized_value: Box = TypedReflectDeserializer::new(value_registration, &type_registry) .deserialize(&value) .map_err(BrpError::resource_error)?; @@ -1372,14 +1373,14 @@ fn reflect_component_from_id( fn deserialize_components( type_registry: &TypeRegistry, components: HashMap, -) -> AnyhowResult>> { +) -> AnyhowResult>> { let mut reflect_components = vec![]; for (component_path, component) in components { let Some(component_type) = type_registry.get_with_type_path(&component_path) else { return Err(anyhow!("Unknown component type: `{}`", component_path)); }; - let reflected: Box = + let reflected: Box = TypedReflectDeserializer::new(component_type, type_registry) .deserialize(&component) .map_err(|err| anyhow!("{component_path} is invalid: {err}"))?; @@ -1395,11 +1396,11 @@ fn deserialize_resource( type_registry: &TypeRegistry, resource_path: &str, value: Value, -) -> AnyhowResult> { +) -> AnyhowResult> { let Some(resource_type) = type_registry.get_with_type_path(resource_path) else { return Err(anyhow!("Unknown resource type: `{}`", resource_path)); }; - let reflected: Box = + let reflected: Box = TypedReflectDeserializer::new(resource_type, type_registry) .deserialize(&value) .map_err(|err| anyhow!("{resource_path} is invalid: {err}"))?; @@ -1411,7 +1412,7 @@ fn deserialize_resource( fn insert_reflected_components( type_registry: &TypeRegistry, mut entity_world_mut: EntityWorldMut, - reflect_components: Vec>, + reflect_components: Vec>, ) -> AnyhowResult<()> { for reflected in reflect_components { let reflect_component = diff --git a/crates/bevy_scene/src/dynamic_scene.rs b/crates/bevy_scene/src/dynamic_scene.rs index f0cf3960d60ea..5a2023689bb48 100644 --- a/crates/bevy_scene/src/dynamic_scene.rs +++ b/crates/bevy_scene/src/dynamic_scene.rs @@ -29,7 +29,7 @@ use { #[derive(Asset, TypePath, Default)] pub struct DynamicScene { /// Resources stored in the dynamic scene. - pub resources: Vec>, + pub resources: Vec>, /// Entities contained in the dynamic scene. pub entities: Vec, } @@ -42,7 +42,7 @@ pub struct DynamicEntity { pub entity: Entity, /// A vector of boxed components that belong to the given entity and /// implement the [`PartialReflect`] trait. - pub components: Vec>, + pub components: Vec>, } impl DynamicScene { diff --git a/crates/bevy_scene/src/dynamic_scene_builder.rs b/crates/bevy_scene/src/dynamic_scene_builder.rs index 5deac09aaa073..6e7dc62528ec2 100644 --- a/crates/bevy_scene/src/dynamic_scene_builder.rs +++ b/crates/bevy_scene/src/dynamic_scene_builder.rs @@ -59,7 +59,7 @@ use bevy_utils::default; /// /// [`Reflect`]: bevy_reflect::Reflect pub struct DynamicSceneBuilder<'w> { - extracted_resources: BTreeMap>, + extracted_resources: BTreeMap>, extracted_scene: BTreeMap, component_filter: SceneFilter, resource_filter: SceneFilter, diff --git a/crates/bevy_scene/src/reflect_utils.rs b/crates/bevy_scene/src/reflect_utils.rs index bf69dd035295a..f0772d1de11fa 100644 --- a/crates/bevy_scene/src/reflect_utils.rs +++ b/crates/bevy_scene/src/reflect_utils.rs @@ -9,9 +9,9 @@ use bevy_reflect::{PartialReflect, ReflectFromReflect, TypeRegistration}; /// This helps ensure that the original type and type data is retained, /// and only returning a dynamic type if all other methods fail. pub(super) fn clone_reflect_value( - value: &dyn PartialReflect, + value: &(dyn PartialReflect + Send + Sync), type_registration: &TypeRegistration, -) -> Box { +) -> Box { value .reflect_clone() .map(PartialReflect::into_partial_reflect) diff --git a/crates/bevy_scene/src/serde.rs b/crates/bevy_scene/src/serde.rs index 526069b5ab0ac..15e9bdc7fe653 100644 --- a/crates/bevy_scene/src/serde.rs +++ b/crates/bevy_scene/src/serde.rs @@ -158,7 +158,7 @@ impl<'a> Serialize for EntitySerializer<'a> { /// Note: The entries are sorted by type path before they're serialized. pub struct SceneMapSerializer<'a> { /// List of boxed values of unique type to serialize. - pub entries: &'a [Box], + pub entries: &'a [Box], /// Type registry in which the types used in `entries` are registered. pub registry: &'a TypeRegistry, } @@ -245,7 +245,7 @@ impl<'a, 'de> Visitor<'de> for SceneVisitor<'a> { where A: SeqAccess<'de>, { - let resources = seq + let resources: Vec> = seq .next_element_seed(SceneMapDeserializer { registry: self.type_registry, })? @@ -437,7 +437,7 @@ pub struct SceneMapDeserializer<'a> { } impl<'a, 'de> DeserializeSeed<'de> for SceneMapDeserializer<'a> { - type Value = Vec>; + type Value = Vec>; fn deserialize(self, deserializer: D) -> Result where @@ -454,7 +454,7 @@ struct SceneMapVisitor<'a> { } impl<'a, 'de> Visitor<'de> for SceneMapVisitor<'a> { - type Value = Vec>; + type Value = Vec>; fn expecting(&self, formatter: &mut Formatter) -> core::fmt::Result { formatter.write_str("map of reflect types") diff --git a/crates/bevy_state/src/reflect.rs b/crates/bevy_state/src/reflect.rs index 0ff09c3759d21..65f346716c838 100644 --- a/crates/bevy_state/src/reflect.rs +++ b/crates/bevy_state/src/reflect.rs @@ -14,7 +14,7 @@ pub struct ReflectState(ReflectStateFns); #[derive(Clone)] pub struct ReflectStateFns { /// Function pointer implementing [`ReflectState::reflect()`]. - pub reflect: fn(&World) -> Option<&dyn Reflect>, + pub reflect: fn(&World) -> Option<&(dyn Reflect + Send + Sync)>, } impl ReflectStateFns { @@ -23,25 +23,25 @@ impl ReflectStateFns { /// /// This is useful if you want to start with the default implementation before overriding some /// of the functions to create a custom implementation. - pub fn new() -> Self { + pub fn new() -> Self { >::from_type().0 } } impl ReflectState { /// Gets the value of this [`States`] type from the world as a reflected reference. - pub fn reflect<'a>(&self, world: &'a World) -> Option<&'a dyn Reflect> { + pub fn reflect<'a>(&self, world: &'a World) -> Option<&'a (dyn Reflect + Send + Sync)> { (self.0.reflect)(world) } } -impl FromType for ReflectState { +impl FromType for ReflectState { fn from_type() -> Self { ReflectState(ReflectStateFns { reflect: |world| { world .get_resource::>() - .map(|res| res.get() as &dyn Reflect) + .map(|res| res.get() as &(dyn Reflect + Send + Sync)) }, }) } @@ -58,7 +58,7 @@ pub struct ReflectFreelyMutableState(ReflectFreelyMutableStateFns); #[derive(Clone)] pub struct ReflectFreelyMutableStateFns { /// Function pointer implementing [`ReflectFreelyMutableState::set_next_state()`]. - pub set_next_state: fn(&mut World, &dyn Reflect, &TypeRegistry), + pub set_next_state: fn(&mut World, &(dyn Reflect + Send + Sync), &TypeRegistry), } impl ReflectFreelyMutableStateFns { @@ -74,7 +74,12 @@ impl ReflectFreelyMutableStateFns { impl ReflectFreelyMutableState { /// Tentatively set a pending state transition to a reflected [`ReflectFreelyMutableState`]. - pub fn set_next_state(&self, world: &mut World, state: &dyn Reflect, registry: &TypeRegistry) { + pub fn set_next_state( + &self, + world: &mut World, + state: &(dyn Reflect + Send + Sync), + registry: &TypeRegistry, + ) { (self.0.set_next_state)(world, state, registry); } } diff --git a/examples/picking/sprite_picking.rs b/examples/picking/sprite_picking.rs index 126336bf29cdf..3854a405db8e5 100644 --- a/examples/picking/sprite_picking.rs +++ b/examples/picking/sprite_picking.rs @@ -150,7 +150,9 @@ fn setup_atlas( } // An observer listener that changes the target entity's color. -fn recolor_on(color: Color) -> impl Fn(Trigger, Query<&mut Sprite>) { +fn recolor_on( + color: Color, +) -> impl Fn(Trigger, Query<&mut Sprite>) { move |ev, mut sprites| { let Ok(mut sprite) = sprites.get_mut(ev.target()) else { return; diff --git a/examples/reflection/custom_attributes.rs b/examples/reflection/custom_attributes.rs index f75a0a8d3e7e0..e949bba6752db 100644 --- a/examples/reflection/custom_attributes.rs +++ b/examples/reflection/custom_attributes.rs @@ -58,7 +58,8 @@ fn main() { // We can also get attribute data dynamically: let some_type_id = TypeId::of::(); - let tooltip: &dyn Reflect = type_info.get_attribute_by_id(some_type_id).unwrap(); + let tooltip: &(dyn Reflect + Send + Sync) = + type_info.get_attribute_by_id(some_type_id).unwrap(); assert_eq!( tooltip.downcast_ref::(), Some(&Tooltip::new("An ID is required!")) diff --git a/examples/reflection/dynamic_types.rs b/examples/reflection/dynamic_types.rs index 772ffe1dd24dd..abd1d20594d95 100644 --- a/examples/reflection/dynamic_types.rs +++ b/examples/reflection/dynamic_types.rs @@ -37,7 +37,7 @@ fn main() { // This trait object also gives us access to all the methods in the `PartialReflect` trait too. // The underlying type is still the same (in this case, `Player`), // but now we've hidden that information from the compiler. - let reflected: Box = Box::new(player); + let reflected: Box = Box::new(player); // Because it's the same type under the hood, we can still downcast it back to the original type. assert!(reflected.downcast_ref::().is_some()); @@ -45,14 +45,14 @@ fn main() { // We can attempt to clone our value using `PartialReflect::reflect_clone`. // This will recursively call `PartialReflect::reflect_clone` on all fields of the type. // Or, if we had registered `ReflectClone` using `#[reflect(Clone)]`, it would simply call `Clone::clone` directly. - let cloned: Box = reflected.reflect_clone().unwrap(); + let cloned: Box = reflected.reflect_clone().unwrap(); assert_eq!(cloned.downcast_ref::(), Some(&Player { id: 123 })); // Another way we can "clone" our data is by converting it to a dynamic type. // Notice here we bind it as a `dyn PartialReflect` instead of `dyn Reflect`. // This is because it returns a dynamic type that simply represents the original type. // In this case, because `Player` is a struct, it will return a `DynamicStruct`. - let dynamic: Box = reflected.to_dynamic(); + let dynamic: Box = reflected.to_dynamic(); assert!(dynamic.is_dynamic()); // And if we try to convert it back to a `dyn Reflect` trait object, we'll get `None`. @@ -114,7 +114,7 @@ fn main() { .data::() .expect("`ReflectDefault` should be registered"); - let mut value: Box = reflect_default.default(); + let mut value: Box = reflect_default.default(); value.apply(deserialized.as_ref()); let identifiable: &dyn Identifiable = reflect_identifiable.get(value.as_reflect()).unwrap(); @@ -134,7 +134,7 @@ fn main() { .data::() .expect("`ReflectFromReflect` should be registered"); - let value: Box = reflect_from_reflect + let value: Box = reflect_from_reflect .from_reflect(deserialized.as_ref()) .unwrap(); let identifiable: &dyn Identifiable = reflect_identifiable.get(value.as_reflect()).unwrap(); diff --git a/examples/reflection/function_reflection.rs b/examples/reflection/function_reflection.rs index 4a4f97497ec67..333328cd5cedf 100644 --- a/examples/reflection/function_reflection.rs +++ b/examples/reflection/function_reflection.rs @@ -54,7 +54,7 @@ fn main() { // The `Return` value can be pattern matched or unwrapped to get the underlying reflection data. // For the sake of brevity, we'll just unwrap it here and downcast it to the expected type of `i32`. - let value: Box = return_value.unwrap_owned(); + let value: Box = return_value.unwrap_owned(); assert_eq!(value.try_take::().unwrap(), 4); // The same can also be done for closures that capture references to their environment. @@ -66,7 +66,7 @@ fn main() { let function: DynamicFunction = dbg!(clamp.into_function()); let args = dbg!(ArgList::new().with_owned(2_i32)); let return_value = dbg!(function.call(args).unwrap()); - let value: Box = return_value.unwrap_owned(); + let value: Box = return_value.unwrap_owned(); assert_eq!(value.try_take::().unwrap(), 5); // We can also handle closures that capture their environment mutably @@ -94,7 +94,7 @@ fn main() { let args = ArgList::new().with_owned(123_i32); let return_value = function.call(args).unwrap(); - let value: Box = return_value.unwrap_owned(); + let value: Box = return_value.unwrap_owned(); assert_eq!(value.try_take::().unwrap(), "123"); // To make things a little easier, we can also "overload" functions. @@ -108,7 +108,7 @@ fn main() { // Now our `function` accepts both `i32` and `f32` arguments. let args = ArgList::new().with_owned(1.23_f32); let return_value = function.call(args).unwrap(); - let value: Box = return_value.unwrap_owned(); + let value: Box = return_value.unwrap_owned(); assert_eq!(value.try_take::().unwrap(), "1.23"); // Function overloading even allows us to have a variable number of arguments. @@ -123,7 +123,7 @@ fn main() { .with_owned(2_i32) .with_owned(3_i32); let return_value = function.call(args).unwrap(); - let value: Box = return_value.unwrap_owned(); + let value: Box = return_value.unwrap_owned(); assert_eq!(value.try_take::().unwrap(), 6); // As stated earlier, `IntoFunction` works for many kinds of simple functions. @@ -158,7 +158,7 @@ fn main() { let get_value = dbg!(Data::get_value.into_function()); let args = dbg!(ArgList::new().with_ref(&data)); let return_value = dbg!(get_value.call(args).unwrap()); - let value: &dyn PartialReflect = return_value.unwrap_ref(); + let value: &(dyn PartialReflect + Send + Sync) = return_value.unwrap_ref(); assert_eq!(value.try_downcast_ref::().unwrap(), "Hello, world!"); // For more complex use cases, you can always create a custom `DynamicFunction` manually. diff --git a/examples/reflection/reflection.rs b/examples/reflection/reflection.rs index f2130c35de37f..7b7ca1d6e51e3 100644 --- a/examples/reflection/reflection.rs +++ b/examples/reflection/reflection.rs @@ -65,7 +65,7 @@ fn setup(type_registry: Res) { assert_eq!(value.a, 2); assert_eq!(*value.get_field::("a").unwrap(), 2); - // You can also get the `&dyn PartialReflect` value of a field like this + // You can also get the `&(dyn PartialReflect + Send + Sync)` value of a field like this let field = value.field("a").unwrap(); // But values introspected via `PartialReflect` will not return `dyn Reflect` trait objects @@ -101,7 +101,7 @@ fn setup(type_registry: Res) { let mut deserializer = ron::de::Deserializer::from_str(&ron_string).unwrap(); let reflect_value = reflect_deserializer.deserialize(&mut deserializer).unwrap(); - // Deserializing returns a `Box` value. + // Deserializing returns a `Box` value. // Generally, deserializing a value will return the "dynamic" variant of a type. // For example, deserializing a struct will return the DynamicStruct type. // "Opaque types" will be deserialized as themselves. diff --git a/examples/reflection/reflection_types.rs b/examples/reflection/reflection_types.rs index 427034056f1b4..76a0a1fb7de32 100644 --- a/examples/reflection/reflection_types.rs +++ b/examples/reflection/reflection_types.rs @@ -67,7 +67,7 @@ enum F { fn setup() { let mut z = >::default(); z.insert("Hello".to_string(), 1.0); - let value: Box = Box::new(A { + let value: Box = Box::new(A { x: 1, y: vec![1, 2], z, diff --git a/examples/reflection/type_data.rs b/examples/reflection/type_data.rs index 56dafa8522d6e..7488932ea2d60 100644 --- a/examples/reflection/type_data.rs +++ b/examples/reflection/type_data.rs @@ -27,8 +27,8 @@ fn main() { // Let's say we have a reflected value. // Here we know it's a `Zombie`, but for demonstration purposes let's pretend we don't. - // Pretend it's just some `Box` value. - let mut value: Box = Box::new(Zombie { health: 100 }); + // Pretend it's just some `Box` value. + let mut value: Box = Box::new(Zombie { health: 100 }); // We think `value` might contain a type that implements `Damageable` // and now we want to call `Damageable::damage` on it. @@ -49,12 +49,20 @@ fn main() { // Just remember that we're working with `Reflect` data, // so we can't use `Self`, generics, or associated types. // In those cases, we'll have to use `dyn Reflect` trait objects. - damage: fn(&mut dyn Reflect, damage: Box), + damage: fn(&mut (dyn Reflect + Send + Sync), damage: Box), } // Now, we can create a blanket implementation of the `FromType` trait to construct our type data // for any type that implements `Reflect` and `Damageable`. - impl> FromType for ReflectDamageable { + impl< + T: Reflect + + Send + + Sync + + Damageable + + Send + + Sync, + > FromType for ReflectDamageable + { fn from_type() -> Self { Self { damage: |reflect, damage| { @@ -70,7 +78,11 @@ fn main() { // It's also common to provide convenience methods for calling the type-specific operations. impl ReflectDamageable { - pub fn damage(&self, reflect: &mut dyn Reflect, damage: Box) { + pub fn damage( + &self, + reflect: &mut (dyn Reflect + Send + Sync), + damage: Box, + ) { (self.damage)(reflect, damage); } } @@ -133,14 +145,14 @@ fn main() { registry.register_type_data::(); // Now we can use `ReflectHealth` to convert `dyn Reflect` into `dyn Health`: - let value: Box = Box::new(Skeleton { health: 50 }); + let value: Box = Box::new(Skeleton { health: 50 }); let type_id = value.reflect_type_info().type_id(); let reflect_health = registry.get_type_data::(type_id).unwrap(); // Type data generated by `#[reflect_trait]` comes with a `get`, `get_mut`, and `get_boxed` method, - // which convert `&dyn Reflect` into `&dyn MyTrait`, `&mut dyn Reflect` into `&mut dyn MyTrait`, - // and `Box` into `Box`, respectively. + // which convert `&(dyn Reflect + Send + Sync)` into `&dyn MyTrait`, `&mut (dyn Reflect + Send + Sync)` into `&mut dyn MyTrait`, + // and `Box` into `Box`, respectively. let value: &dyn Health = reflect_health.get(value.as_reflect()).unwrap(); assert_eq!(value.health(), 50);