From 1568d4a415fdbe8795a60d09aa38ba5f5faf831c Mon Sep 17 00:00:00 2001 From: Tygyh <32486062+tygyh@users.noreply.github.com> Date: Sun, 24 Dec 2023 18:43:55 +0100 Subject: [PATCH] Reorder impl to be the same as the trait (#11076) # Objective - Make the implementation order consistent between all sources to fit the order in the trait. ## Solution - Change the implementation order. --- crates/bevy_asset/src/io/file/file_asset.rs | 68 ++++++++-------- crates/bevy_asset/src/lib.rs | 68 ++++++++-------- crates/bevy_asset/src/loader.rs | 16 ++-- crates/bevy_asset/src/meta.rs | 10 +-- crates/bevy_asset/src/path.rs | 8 +- crates/bevy_audio/src/audio_source.rs | 2 +- crates/bevy_gizmos/src/lib.rs | 4 +- crates/bevy_pbr/src/extended_material.rs | 32 ++++---- crates/bevy_pbr/src/pbr_material.rs | 88 ++++++++++----------- crates/bevy_reflect/src/array.rs | 10 +-- crates/bevy_reflect/src/impls/std.rs | 42 +++++----- crates/bevy_reflect/src/lib.rs | 8 +- crates/bevy_reflect/src/map.rs | 40 +++++----- crates/bevy_reflect/src/serde/de.rs | 88 ++++++++++----------- crates/bevy_reflect/src/struct_trait.rs | 38 ++++----- crates/bevy_reflect/src/tuple.rs | 20 ++--- crates/bevy_reflect/src/tuple_struct.rs | 36 ++++----- crates/bevy_render/src/render_graph/app.rs | 16 ++-- crates/bevy_scene/src/serde.rs | 72 ++++++++--------- crates/bevy_transform/src/commands.rs | 12 +-- crates/bevy_utils/src/lib.rs | 20 ++--- examples/2d/custom_gltf_vertex_attribute.rs | 4 +- examples/audio/decodable.rs | 4 +- 23 files changed, 353 insertions(+), 353 deletions(-) diff --git a/crates/bevy_asset/src/io/file/file_asset.rs b/crates/bevy_asset/src/io/file/file_asset.rs index 7fd95cde35..aa20913140 100644 --- a/crates/bevy_asset/src/io/file/file_asset.rs +++ b/crates/bevy_asset/src/io/file/file_asset.rs @@ -155,40 +155,6 @@ impl AssetWriter for FileAssetWriter { }) } - fn remove_directory<'a>( - &'a self, - path: &'a Path, - ) -> BoxedFuture<'a, Result<(), AssetWriterError>> { - Box::pin(async move { - let full_path = self.root_path.join(path); - async_fs::remove_dir_all(full_path).await?; - Ok(()) - }) - } - - fn remove_empty_directory<'a>( - &'a self, - path: &'a Path, - ) -> BoxedFuture<'a, Result<(), AssetWriterError>> { - Box::pin(async move { - let full_path = self.root_path.join(path); - async_fs::remove_dir(full_path).await?; - Ok(()) - }) - } - - fn remove_assets_in_directory<'a>( - &'a self, - path: &'a Path, - ) -> BoxedFuture<'a, Result<(), AssetWriterError>> { - Box::pin(async move { - let full_path = self.root_path.join(path); - async_fs::remove_dir_all(&full_path).await?; - async_fs::create_dir_all(&full_path).await?; - Ok(()) - }) - } - fn rename<'a>( &'a self, old_path: &'a Path, @@ -222,4 +188,38 @@ impl AssetWriter for FileAssetWriter { Ok(()) }) } + + fn remove_directory<'a>( + &'a self, + path: &'a Path, + ) -> BoxedFuture<'a, Result<(), AssetWriterError>> { + Box::pin(async move { + let full_path = self.root_path.join(path); + async_fs::remove_dir_all(full_path).await?; + Ok(()) + }) + } + + fn remove_empty_directory<'a>( + &'a self, + path: &'a Path, + ) -> BoxedFuture<'a, Result<(), AssetWriterError>> { + Box::pin(async move { + let full_path = self.root_path.join(path); + async_fs::remove_dir(full_path).await?; + Ok(()) + }) + } + + fn remove_assets_in_directory<'a>( + &'a self, + path: &'a Path, + ) -> BoxedFuture<'a, Result<(), AssetWriterError>> { + Box::pin(async move { + let full_path = self.root_path.join(path); + async_fs::remove_dir_all(&full_path).await?; + async_fs::create_dir_all(&full_path).await?; + Ok(()) + }) + } } diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index 552e69a134..321ad57937 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -320,6 +320,40 @@ impl AssetApp for App { self } + fn register_asset_processor(&mut self, processor: P) -> &mut Self { + if let Some(asset_processor) = self.world.get_resource::() { + asset_processor.register_processor(processor); + } + self + } + + fn register_asset_source( + &mut self, + id: impl Into>, + source: AssetSourceBuilder, + ) -> &mut Self { + let id = id.into(); + if self.world.get_resource::().is_some() { + error!("{} must be registered before `AssetPlugin` (typically added as part of `DefaultPlugins`)", id); + } + + { + let mut sources = self + .world + .get_resource_or_insert_with(AssetSourceBuilders::default); + sources.insert(id, source); + } + + self + } + + fn set_default_asset_processor(&mut self, extension: &str) -> &mut Self { + if let Some(asset_processor) = self.world.get_resource::() { + asset_processor.set_default_processor::

(extension); + } + self + } + fn init_asset_loader(&mut self) -> &mut Self { let loader = L::from_world(&mut self.world); self.register_asset_loader(loader) @@ -372,40 +406,6 @@ impl AssetApp for App { .preregister_loader::(extensions); self } - - fn register_asset_processor(&mut self, processor: P) -> &mut Self { - if let Some(asset_processor) = self.world.get_resource::() { - asset_processor.register_processor(processor); - } - self - } - - fn set_default_asset_processor(&mut self, extension: &str) -> &mut Self { - if let Some(asset_processor) = self.world.get_resource::() { - asset_processor.set_default_processor::

(extension); - } - self - } - - fn register_asset_source( - &mut self, - id: impl Into>, - source: AssetSourceBuilder, - ) -> &mut Self { - let id = id.into(); - if self.world.get_resource::().is_some() { - error!("{} must be registered before `AssetPlugin` (typically added as part of `DefaultPlugins`)", id); - } - - { - let mut sources = self - .world - .get_resource_or_insert_with(AssetSourceBuilders::default); - sources.insert(id, source); - } - - self - } } /// A system set that holds all "track asset" operations. diff --git a/crates/bevy_asset/src/loader.rs b/crates/bevy_asset/src/loader.rs index 26f7ebc6a0..895d6b123a 100644 --- a/crates/bevy_asset/src/loader.rs +++ b/crates/bevy_asset/src/loader.rs @@ -97,6 +97,10 @@ where }) } + fn extensions(&self) -> &[&str] { + ::extensions(self) + } + fn deserialize_meta(&self, meta: &[u8]) -> Result, DeserializeMetaError> { let meta = AssetMeta::::deserialize(meta)?; Ok(Box::new(meta)) @@ -109,10 +113,6 @@ where })) } - fn extensions(&self) -> &[&str] { - ::extensions(self) - } - fn type_name(&self) -> &'static str { std::any::type_name::() } @@ -121,13 +121,13 @@ where TypeId::of::() } - fn asset_type_id(&self) -> TypeId { - TypeId::of::() - } - fn asset_type_name(&self) -> &'static str { std::any::type_name::() } + + fn asset_type_id(&self) -> TypeId { + TypeId::of::() + } } pub(crate) struct LabeledAsset { diff --git a/crates/bevy_asset/src/meta.rs b/crates/bevy_asset/src/meta.rs index dbcd7d7feb..e8758999f7 100644 --- a/crates/bevy_asset/src/meta.rs +++ b/crates/bevy_asset/src/meta.rs @@ -128,11 +128,6 @@ pub trait AssetMetaDyn: Downcast + Send + Sync { } impl AssetMetaDyn for AssetMeta { - fn serialize(&self) -> Vec { - ron::ser::to_string_pretty(&self, PrettyConfig::default()) - .expect("type is convertible to ron") - .into_bytes() - } fn loader_settings(&self) -> Option<&dyn Settings> { if let AssetAction::Load { settings, .. } = &self.asset { Some(settings) @@ -147,6 +142,11 @@ impl AssetMetaDyn for AssetMeta { None } } + fn serialize(&self) -> Vec { + ron::ser::to_string_pretty(&self, PrettyConfig::default()) + .expect("type is convertible to ron") + .into_bytes() + } fn processed_info(&self) -> &Option { &self.processed_info } diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index f321fc2154..21dbebab85 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -626,10 +626,6 @@ impl Reflect for AssetPath<'static> { self } #[inline] - fn clone_value(&self) -> Box { - Box::new(self.clone()) - } - #[inline] fn apply(&mut self, value: &dyn Reflect) { let value = Reflect::as_any(value); if let Some(value) = value.downcast_ref::() { @@ -655,6 +651,10 @@ impl Reflect for AssetPath<'static> { fn reflect_owned(self: Box) -> ReflectOwned { ReflectOwned::Value(self) } + #[inline] + fn clone_value(&self) -> Box { + Box::new(self.clone()) + } fn reflect_hash(&self) -> Option { let mut hasher = bevy_reflect::utility::reflect_hasher(); Hash::hash(&::core::any::Any::type_id(self), &mut hasher); diff --git a/crates/bevy_audio/src/audio_source.rs b/crates/bevy_audio/src/audio_source.rs index 30f9c8cf8d..8b0c7090ea 100644 --- a/crates/bevy_audio/src/audio_source.rs +++ b/crates/bevy_audio/src/audio_source.rs @@ -97,8 +97,8 @@ pub trait Decodable: Send + Sync + 'static { } impl Decodable for AudioSource { - type Decoder = rodio::Decoder>; type DecoderItem = > as Iterator>::Item; + type Decoder = rodio::Decoder>; fn decoder(&self) -> Self::Decoder { rodio::Decoder::new(Cursor::new(self.clone())).unwrap() diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 26864664ad..178b9680ca 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -431,9 +431,9 @@ fn prepare_line_gizmo_bind_group( struct SetLineGizmoBindGroup; impl RenderCommand

for SetLineGizmoBindGroup { + type Param = SRes; type ViewData = (); type ItemData = Read>; - type Param = SRes; #[inline] fn render<'w>( @@ -454,9 +454,9 @@ impl RenderCommand

for SetLineGizmoBindGroup struct DrawLineGizmo; impl RenderCommand

for DrawLineGizmo { + type Param = SRes>; type ViewData = (); type ItemData = Read>; - type Param = SRes>; #[inline] fn render<'w>( diff --git a/crates/bevy_pbr/src/extended_material.rs b/crates/bevy_pbr/src/extended_material.rs index dacacd5cf3..a80a6d5af5 100644 --- a/crates/bevy_pbr/src/extended_material.rs +++ b/crates/bevy_pbr/src/extended_material.rs @@ -167,6 +167,22 @@ impl Material for ExtendedMaterial { } } + fn alpha_mode(&self) -> crate::AlphaMode { + B::alpha_mode(&self.base) + } + + fn opaque_render_method(&self) -> crate::OpaqueRendererMethod { + B::opaque_render_method(&self.base) + } + + fn depth_bias(&self) -> f32 { + B::depth_bias(&self.base) + } + + fn reads_view_transmission_texture(&self) -> bool { + B::reads_view_transmission_texture(&self.base) + } + fn prepass_vertex_shader() -> ShaderRef { match E::prepass_vertex_shader() { ShaderRef::Default => B::prepass_vertex_shader(), @@ -195,22 +211,6 @@ impl Material for ExtendedMaterial { } } - fn alpha_mode(&self) -> crate::AlphaMode { - B::alpha_mode(&self.base) - } - - fn depth_bias(&self) -> f32 { - B::depth_bias(&self.base) - } - - fn reads_view_transmission_texture(&self) -> bool { - B::reads_view_transmission_texture(&self.base) - } - - fn opaque_render_method(&self) -> crate::OpaqueRendererMethod { - B::opaque_render_method(&self.base) - } - fn specialize( pipeline: &MaterialPipeline, descriptor: &mut RenderPipelineDescriptor, diff --git a/crates/bevy_pbr/src/pbr_material.rs b/crates/bevy_pbr/src/pbr_material.rs index 178b805395..d65eb12afa 100644 --- a/crates/bevy_pbr/src/pbr_material.rs +++ b/crates/bevy_pbr/src/pbr_material.rs @@ -750,6 +750,50 @@ impl From<&StandardMaterial> for StandardMaterialKey { } impl Material for StandardMaterial { + fn fragment_shader() -> ShaderRef { + PBR_SHADER_HANDLE.into() + } + + #[inline] + fn alpha_mode(&self) -> AlphaMode { + self.alpha_mode + } + + #[inline] + fn opaque_render_method(&self) -> OpaqueRendererMethod { + match self.opaque_render_method { + // For now, diffuse transmission doesn't work under deferred rendering as we don't pack + // the required data into the GBuffer. If this material is set to `Auto`, we report it as + // `Forward` so that it's rendered correctly, even when the `DefaultOpaqueRendererMethod` + // is set to `Deferred`. + // + // If the developer explicitly sets the `OpaqueRendererMethod` to `Deferred`, we assume + // they know what they're doing and don't override it. + OpaqueRendererMethod::Auto if self.diffuse_transmission > 0.0 => { + OpaqueRendererMethod::Forward + } + other => other, + } + } + + #[inline] + fn depth_bias(&self) -> f32 { + self.depth_bias + } + + #[inline] + fn reads_view_transmission_texture(&self) -> bool { + self.specular_transmission > 0.0 + } + + fn prepass_fragment_shader() -> ShaderRef { + PBR_PREPASS_SHADER_HANDLE.into() + } + + fn deferred_fragment_shader() -> ShaderRef { + PBR_SHADER_HANDLE.into() + } + fn specialize( _pipeline: &MaterialPipeline, descriptor: &mut RenderPipelineDescriptor, @@ -775,48 +819,4 @@ impl Material for StandardMaterial { } Ok(()) } - - fn prepass_fragment_shader() -> ShaderRef { - PBR_PREPASS_SHADER_HANDLE.into() - } - - fn deferred_fragment_shader() -> ShaderRef { - PBR_SHADER_HANDLE.into() - } - - fn fragment_shader() -> ShaderRef { - PBR_SHADER_HANDLE.into() - } - - #[inline] - fn alpha_mode(&self) -> AlphaMode { - self.alpha_mode - } - - #[inline] - fn depth_bias(&self) -> f32 { - self.depth_bias - } - - #[inline] - fn reads_view_transmission_texture(&self) -> bool { - self.specular_transmission > 0.0 - } - - #[inline] - fn opaque_render_method(&self) -> OpaqueRendererMethod { - match self.opaque_render_method { - // For now, diffuse transmission doesn't work under deferred rendering as we don't pack - // the required data into the GBuffer. If this material is set to `Auto`, we report it as - // `Forward` so that it's rendered correctly, even when the `DefaultOpaqueRendererMethod` - // is set to `Deferred`. - // - // If the developer explicitly sets the `OpaqueRendererMethod` to `Deferred`, we assume - // they know what they're doing and don't override it. - OpaqueRendererMethod::Auto if self.diffuse_transmission > 0.0 => { - OpaqueRendererMethod::Forward - } - other => other, - } - } } diff --git a/crates/bevy_reflect/src/array.rs b/crates/bevy_reflect/src/array.rs index 1497aeb149..82e6fb53d9 100644 --- a/crates/bevy_reflect/src/array.rs +++ b/crates/bevy_reflect/src/array.rs @@ -297,16 +297,16 @@ impl Reflect for DynamicArray { array_partial_eq(self, value) } - #[inline] - fn is_dynamic(&self) -> bool { - true - } - fn debug(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "DynamicArray(")?; array_debug(self, f)?; write!(f, ")") } + + #[inline] + fn is_dynamic(&self) -> bool { + true + } } impl Array for DynamicArray { diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index 4fd1043e31..2a6e7dde00 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -1162,23 +1162,6 @@ impl List for Cow<'static, [T]> { self.to_mut().get_mut(index).map(|x| x as &mut dyn Reflect) } - fn len(&self) -> usize { - self.as_ref().len() - } - - fn iter(&self) -> ListIter { - ListIter::new(self) - } - - fn drain(self: Box) -> Vec> { - // into_owned() is not unnecessary here because it avoids cloning whenever you have a Cow::Owned already - #[allow(clippy::unnecessary_to_owned)] - self.into_owned() - .into_iter() - .map(|value| value.clone_value()) - .collect() - } - fn insert(&mut self, index: usize, element: Box) { let value = element.take::().unwrap_or_else(|value| { T::from_reflect(&*value).unwrap_or_else(|| { @@ -1210,9 +1193,30 @@ impl List for Cow<'static, [T]> { .pop() .map(|value| Box::new(value) as Box) } + + fn len(&self) -> usize { + self.as_ref().len() + } + + fn iter(&self) -> ListIter { + ListIter::new(self) + } + + fn drain(self: Box) -> Vec> { + // into_owned() is not unnecessary here because it avoids cloning whenever you have a Cow::Owned already + #[allow(clippy::unnecessary_to_owned)] + self.into_owned() + .into_iter() + .map(|value| value.clone_value()) + .collect() + } } impl Reflect for Cow<'static, [T]> { + fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { + Some(::type_info()) + } + fn into_any(self: Box) -> Box { self } @@ -1269,10 +1273,6 @@ impl Reflect for Cow<'static, [T]> { fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option { crate::list_partial_eq(self, value) } - - fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { - Some(::type_info()) - } } impl Typed for Cow<'static, [T]> { diff --git a/crates/bevy_reflect/src/lib.rs b/crates/bevy_reflect/src/lib.rs index 72fe7a8507..3ed140c6f2 100644 --- a/crates/bevy_reflect/src/lib.rs +++ b/crates/bevy_reflect/src/lib.rs @@ -1900,6 +1900,10 @@ bevy_reflect::tests::Test { }) } + fn type_ident() -> Option<&'static str> { + Some("Foo") + } + fn crate_name() -> Option<&'static str> { Some("bevy_reflect") } @@ -1907,10 +1911,6 @@ bevy_reflect::tests::Test { fn module_path() -> Option<&'static str> { Some("bevy_reflect::tests") } - - fn type_ident() -> Option<&'static str> { - Some("Foo") - } } // Can use `TypePath` diff --git a/crates/bevy_reflect/src/map.rs b/crates/bevy_reflect/src/map.rs index 3d4e8e58e6..34e41bf5dd 100644 --- a/crates/bevy_reflect/src/map.rs +++ b/crates/bevy_reflect/src/map.rs @@ -248,10 +248,30 @@ impl Map for DynamicMap { .map(move |index| &mut *self.values.get_mut(index).unwrap().1) } + fn get_at(&self, index: usize) -> Option<(&dyn Reflect, &dyn Reflect)> { + self.values + .get(index) + .map(|(key, value)| (&**key, &**value)) + } + + fn get_at_mut(&mut self, index: usize) -> Option<(&dyn Reflect, &mut dyn Reflect)> { + self.values + .get_mut(index) + .map(|(key, value)| (&**key, &mut **value)) + } + fn len(&self) -> usize { self.values.len() } + fn iter(&self) -> MapIter { + MapIter::new(self) + } + + fn drain(self: Box) -> Vec<(Box, Box)> { + self.values + } + fn clone_dynamic(&self) -> DynamicMap { DynamicMap { represented_type: self.represented_type, @@ -264,22 +284,6 @@ impl Map for DynamicMap { } } - fn iter(&self) -> MapIter { - MapIter::new(self) - } - - fn get_at(&self, index: usize) -> Option<(&dyn Reflect, &dyn Reflect)> { - self.values - .get(index) - .map(|(key, value)| (&**key, &**value)) - } - - fn get_at_mut(&mut self, index: usize) -> Option<(&dyn Reflect, &mut dyn Reflect)> { - self.values - .get_mut(index) - .map(|(key, value)| (&**key, &mut **value)) - } - fn insert_boxed( &mut self, key: Box, @@ -306,10 +310,6 @@ impl Map for DynamicMap { let (_key, value) = self.values.remove(index); Some(value) } - - fn drain(self: Box) -> Vec<(Box, Box)> { - self.values - } } impl Reflect for DynamicMap { diff --git a/crates/bevy_reflect/src/serde/de.rs b/crates/bevy_reflect/src/serde/de.rs index a1ceb885f2..0411ca1e2b 100644 --- a/crates/bevy_reflect/src/serde/de.rs +++ b/crates/bevy_reflect/src/serde/de.rs @@ -49,14 +49,14 @@ impl StructLikeInfo for StructInfo { self.type_path() } - fn field_at(&self, index: usize) -> Option<&NamedField> { - self.field_at(index) - } - fn get_field(&self, name: &str) -> Option<&NamedField> { self.field(name) } + fn field_at(&self, index: usize) -> Option<&NamedField> { + self.field_at(index) + } + fn get_field_len(&self) -> usize { self.field_len() } @@ -88,14 +88,14 @@ impl StructLikeInfo for StructVariantInfo { self.name() } - fn field_at(&self, index: usize) -> Option<&NamedField> { - self.field_at(index) - } - fn get_field(&self, name: &str) -> Option<&NamedField> { self.field(name) } + fn field_at(&self, index: usize) -> Option<&NamedField> { + self.field_at(index) + } + fn get_field_len(&self) -> usize { self.field_len() } @@ -573,19 +573,19 @@ impl<'a, 'de> Visitor<'de> for StructVisitor<'a> { formatter.write_str("reflected struct value") } - fn visit_map(self, mut map: V) -> Result - where - V: MapAccess<'de>, - { - visit_struct(&mut map, self.struct_info, self.registration, self.registry) - } - fn visit_seq(self, mut seq: A) -> Result where A: SeqAccess<'de>, { visit_struct_seq(&mut seq, self.struct_info, self.registration, self.registry) } + + fn visit_map(self, mut map: V) -> Result + where + V: MapAccess<'de>, + { + visit_struct(&mut map, self.struct_info, self.registration, self.registry) + } } struct TupleStructVisitor<'a> { @@ -831,6 +831,19 @@ impl<'de> DeserializeSeed<'de> for VariantDeserializer { formatter.write_str("expected either a variant index or variant name") } + fn visit_u32(self, variant_index: u32) -> Result + where + E: Error, + { + self.0.variant_at(variant_index as usize).ok_or_else(|| { + Error::custom(format_args!( + "no variant found at index `{}` on enum `{}`", + variant_index, + self.0.type_path() + )) + }) + } + fn visit_str(self, variant_name: &str) -> Result where E: Error, @@ -844,19 +857,6 @@ impl<'de> DeserializeSeed<'de> for VariantDeserializer { )) }) } - - fn visit_u32(self, variant_index: u32) -> Result - where - E: Error, - { - self.0.variant_at(variant_index as usize).ok_or_else(|| { - Error::custom(format_args!( - "no variant found at index `{}` on enum `{}`", - variant_index, - self.0.type_path() - )) - }) - } } deserializer.deserialize_identifier(VariantVisitor(self.enum_info)) @@ -876,19 +876,19 @@ impl<'a, 'de> Visitor<'de> for StructVariantVisitor<'a> { formatter.write_str("reflected struct variant value") } - fn visit_map(self, mut map: V) -> Result - where - V: MapAccess<'de>, - { - visit_struct(&mut map, self.struct_info, self.registration, self.registry) - } - fn visit_seq(self, mut seq: A) -> Result where A: SeqAccess<'de>, { visit_struct_seq(&mut seq, self.struct_info, self.registration, self.registry) } + + fn visit_map(self, mut map: V) -> Result + where + V: MapAccess<'de>, + { + visit_struct(&mut map, self.struct_info, self.registration, self.registry) + } } struct TupleVariantVisitor<'a> { @@ -925,6 +925,15 @@ impl<'a, 'de> Visitor<'de> for OptionVisitor<'a> { formatter.write_str(self.enum_info.type_path()) } + fn visit_none(self) -> Result + where + E: Error, + { + let mut option = DynamicEnum::default(); + option.set_variant("None", ()); + Ok(option) + } + fn visit_some(self, deserializer: D) -> Result where D: serde::Deserializer<'de>, @@ -951,15 +960,6 @@ impl<'a, 'de> Visitor<'de> for OptionVisitor<'a> { ))), } } - - fn visit_none(self) -> Result - where - E: Error, - { - let mut option = DynamicEnum::default(); - option.set_variant("None", ()); - Ok(option) - } } fn visit_struct<'de, T, V>( diff --git a/crates/bevy_reflect/src/struct_trait.rs b/crates/bevy_reflect/src/struct_trait.rs index 4f2f25bbd7..0788ae045f 100644 --- a/crates/bevy_reflect/src/struct_trait.rs +++ b/crates/bevy_reflect/src/struct_trait.rs @@ -426,9 +426,22 @@ impl Reflect for DynamicStruct { self } - #[inline] - fn clone_value(&self) -> Box { - Box::new(self.clone_dynamic()) + fn apply(&mut self, value: &dyn Reflect) { + if let ReflectRef::Struct(struct_value) = value.reflect_ref() { + for (i, value) in struct_value.iter_fields().enumerate() { + let name = struct_value.name_at(i).unwrap(); + if let Some(v) = self.field_mut(name) { + v.apply(value); + } + } + } else { + panic!("Attempted to apply non-struct type to struct type."); + } + } + + fn set(&mut self, value: Box) -> Result<(), Box> { + *self = value.take()?; + Ok(()) } #[inline] @@ -446,22 +459,9 @@ impl Reflect for DynamicStruct { ReflectOwned::Struct(self) } - fn apply(&mut self, value: &dyn Reflect) { - if let ReflectRef::Struct(struct_value) = value.reflect_ref() { - for (i, value) in struct_value.iter_fields().enumerate() { - let name = struct_value.name_at(i).unwrap(); - if let Some(v) = self.field_mut(name) { - v.apply(value); - } - } - } else { - panic!("Attempted to apply non-struct type to struct type."); - } - } - - fn set(&mut self, value: Box) -> Result<(), Box> { - *self = value.take()?; - Ok(()) + #[inline] + fn clone_value(&self) -> Box { + Box::new(self.clone_dynamic()) } fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option { diff --git a/crates/bevy_reflect/src/tuple.rs b/crates/bevy_reflect/src/tuple.rs index 747fb29e39..bbd973c2f2 100644 --- a/crates/bevy_reflect/src/tuple.rs +++ b/crates/bevy_reflect/src/tuple.rs @@ -335,9 +335,13 @@ impl Reflect for DynamicTuple { self } - #[inline] - fn clone_value(&self) -> Box { - Box::new(self.clone_dynamic()) + fn apply(&mut self, value: &dyn Reflect) { + tuple_apply(self, value); + } + + fn set(&mut self, value: Box) -> Result<(), Box> { + *self = value.take()?; + Ok(()) } #[inline] @@ -355,13 +359,9 @@ impl Reflect for DynamicTuple { ReflectOwned::Tuple(self) } - fn apply(&mut self, value: &dyn Reflect) { - tuple_apply(self, value); - } - - fn set(&mut self, value: Box) -> Result<(), Box> { - *self = value.take()?; - Ok(()) + #[inline] + fn clone_value(&self) -> Box { + Box::new(self.clone_dynamic()) } fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option { diff --git a/crates/bevy_reflect/src/tuple_struct.rs b/crates/bevy_reflect/src/tuple_struct.rs index f0c453575b..8e3a13d971 100644 --- a/crates/bevy_reflect/src/tuple_struct.rs +++ b/crates/bevy_reflect/src/tuple_struct.rs @@ -329,9 +329,21 @@ impl Reflect for DynamicTupleStruct { self } - #[inline] - fn clone_value(&self) -> Box { - Box::new(self.clone_dynamic()) + fn apply(&mut self, value: &dyn Reflect) { + if let ReflectRef::TupleStruct(tuple_struct) = value.reflect_ref() { + for (i, value) in tuple_struct.iter_fields().enumerate() { + if let Some(v) = self.field_mut(i) { + v.apply(value); + } + } + } else { + panic!("Attempted to apply non-TupleStruct type to TupleStruct type."); + } + } + + fn set(&mut self, value: Box) -> Result<(), Box> { + *self = value.take()?; + Ok(()) } #[inline] @@ -349,21 +361,9 @@ impl Reflect for DynamicTupleStruct { ReflectOwned::TupleStruct(self) } - fn apply(&mut self, value: &dyn Reflect) { - if let ReflectRef::TupleStruct(tuple_struct) = value.reflect_ref() { - for (i, value) in tuple_struct.iter_fields().enumerate() { - if let Some(v) = self.field_mut(i) { - v.apply(value); - } - } - } else { - panic!("Attempted to apply non-TupleStruct type to TupleStruct type."); - } - } - - fn set(&mut self, value: Box) -> Result<(), Box> { - *self = value.take()?; - Ok(()) + #[inline] + fn clone_value(&self) -> Box { + Box::new(self.clone_dynamic()) } fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option { diff --git a/crates/bevy_render/src/render_graph/app.rs b/crates/bevy_render/src/render_graph/app.rs index 185260f95b..3d301348a3 100644 --- a/crates/bevy_render/src/render_graph/app.rs +++ b/crates/bevy_render/src/render_graph/app.rs @@ -32,6 +32,14 @@ pub trait RenderGraphApp { } impl RenderGraphApp for App { + fn add_render_sub_graph(&mut self, sub_graph_name: &'static str) -> &mut Self { + let mut render_graph = self.world.get_resource_mut::().expect( + "RenderGraph not found. Make sure you are using add_render_sub_graph on the RenderApp", + ); + render_graph.add_sub_graph(sub_graph_name, RenderGraph::default()); + self + } + fn add_render_graph_node( &mut self, sub_graph_name: &'static str, @@ -81,12 +89,4 @@ impl RenderGraphApp for App { } self } - - fn add_render_sub_graph(&mut self, sub_graph_name: &'static str) -> &mut Self { - let mut render_graph = self.world.get_resource_mut::().expect( - "RenderGraph not found. Make sure you are using add_render_sub_graph on the RenderApp", - ); - render_graph.add_sub_graph(sub_graph_name, RenderGraph::default()); - self - } } diff --git a/crates/bevy_scene/src/serde.rs b/crates/bevy_scene/src/serde.rs index 6ca7d0e301..615403f9bf 100644 --- a/crates/bevy_scene/src/serde.rs +++ b/crates/bevy_scene/src/serde.rs @@ -236,6 +236,28 @@ impl<'a, 'de> Visitor<'de> for SceneVisitor<'a> { formatter.write_str("scene struct") } + fn visit_seq(self, mut seq: A) -> Result + where + A: SeqAccess<'de>, + { + let resources = seq + .next_element_seed(SceneMapDeserializer { + registry: self.type_registry, + })? + .ok_or_else(|| Error::missing_field(SCENE_RESOURCES))?; + + let entities = seq + .next_element_seed(SceneEntitiesDeserializer { + type_registry: self.type_registry, + })? + .ok_or_else(|| Error::missing_field(SCENE_ENTITIES))?; + + Ok(DynamicScene { + resources, + entities, + }) + } + fn visit_map(self, mut map: A) -> Result where A: MapAccess<'de>, @@ -271,28 +293,6 @@ impl<'a, 'de> Visitor<'de> for SceneVisitor<'a> { entities, }) } - - fn visit_seq(self, mut seq: A) -> Result - where - A: SeqAccess<'de>, - { - let resources = seq - .next_element_seed(SceneMapDeserializer { - registry: self.type_registry, - })? - .ok_or_else(|| Error::missing_field(SCENE_RESOURCES))?; - - let entities = seq - .next_element_seed(SceneEntitiesDeserializer { - type_registry: self.type_registry, - })? - .ok_or_else(|| Error::missing_field(SCENE_ENTITIES))?; - - Ok(DynamicScene { - resources, - entities, - }) - } } /// Handles deserialization for a collection of entities. @@ -455,6 +455,20 @@ impl<'a, 'de> Visitor<'de> for SceneMapVisitor<'a> { formatter.write_str("map of reflect types") } + fn visit_seq(self, mut seq: A) -> Result + where + A: SeqAccess<'de>, + { + let mut dynamic_properties = Vec::new(); + while let Some(entity) = + seq.next_element_seed(UntypedReflectDeserializer::new(self.registry))? + { + dynamic_properties.push(entity); + } + + Ok(dynamic_properties) + } + fn visit_map(self, mut map: A) -> Result where A: MapAccess<'de>, @@ -478,20 +492,6 @@ impl<'a, 'de> Visitor<'de> for SceneMapVisitor<'a> { Ok(entries) } - - fn visit_seq(self, mut seq: A) -> Result - where - A: SeqAccess<'de>, - { - let mut dynamic_properties = Vec::new(); - while let Some(entity) = - seq.next_element_seed(UntypedReflectDeserializer::new(self.registry))? - { - dynamic_properties.push(entity); - } - - Ok(dynamic_properties) - } } #[cfg(test)] diff --git a/crates/bevy_transform/src/commands.rs b/crates/bevy_transform/src/commands.rs index abd1ab5d65..0c1f2d2e95 100644 --- a/crates/bevy_transform/src/commands.rs +++ b/crates/bevy_transform/src/commands.rs @@ -86,15 +86,15 @@ pub trait BuildChildrenTransformExt { fn remove_parent_in_place(&mut self) -> &mut Self; } impl<'w, 's, 'a> BuildChildrenTransformExt for EntityCommands<'w, 's, 'a> { - fn remove_parent_in_place(&mut self) -> &mut Self { - let child = self.id(); - self.commands().add(RemoveParentInPlace { child }); - self - } - fn set_parent_in_place(&mut self, parent: Entity) -> &mut Self { let child = self.id(); self.commands().add(AddChildInPlace { child, parent }); self } + + fn remove_parent_in_place(&mut self) -> &mut Self { + let child = self.id(); + self.commands().add(RemoveParentInPlace { child }); + self + } } diff --git a/crates/bevy_utils/src/lib.rs b/crates/bevy_utils/src/lib.rs index 457eb975a1..dd65ea435f 100644 --- a/crates/bevy_utils/src/lib.rs +++ b/crates/bevy_utils/src/lib.rs @@ -211,6 +211,11 @@ pub struct PassHasher { } impl Hasher for PassHasher { + #[inline] + fn finish(&self) -> u64 { + self.hash + } + fn write(&mut self, _bytes: &[u8]) { panic!("can only hash u64 using PassHasher"); } @@ -219,11 +224,6 @@ impl Hasher for PassHasher { fn write_u64(&mut self, i: u64) { self.hash = i; } - - #[inline] - fn finish(&self) -> u64 { - self.hash - } } /// A [`HashMap`] pre-configured to use [`Hashed`] keys and [`PassHash`] passthrough hashing. @@ -281,6 +281,11 @@ pub struct EntityHasher { } impl Hasher for EntityHasher { + #[inline] + fn finish(&self) -> u64 { + self.hash + } + fn write(&mut self, _bytes: &[u8]) { panic!("can only hash u64 using EntityHasher"); } @@ -317,11 +322,6 @@ impl Hasher for EntityHasher { // This is `(MAGIC * index + generation) << 32 + index`, in a single instruction. self.hash = bits.wrapping_mul(UPPER_PHI); } - - #[inline] - fn finish(&self) -> u64 { - self.hash - } } /// A [`HashMap`] pre-configured to use [`EntityHash`] hashing. diff --git a/examples/2d/custom_gltf_vertex_attribute.rs b/examples/2d/custom_gltf_vertex_attribute.rs index 2f602d92b6..2f84665c31 100644 --- a/examples/2d/custom_gltf_vertex_attribute.rs +++ b/examples/2d/custom_gltf_vertex_attribute.rs @@ -61,10 +61,10 @@ fn setup( struct CustomMaterial {} impl Material2d for CustomMaterial { - fn fragment_shader() -> ShaderRef { + fn vertex_shader() -> ShaderRef { "shaders/custom_gltf_2d.wgsl".into() } - fn vertex_shader() -> ShaderRef { + fn fragment_shader() -> ShaderRef { "shaders/custom_gltf_2d.wgsl".into() } diff --git a/examples/audio/decodable.rs b/examples/audio/decodable.rs index 738606cc2a..97028fabb4 100644 --- a/examples/audio/decodable.rs +++ b/examples/audio/decodable.rs @@ -72,10 +72,10 @@ impl Source for SineDecoder { // Finally `Decodable` can be implemented for our `SineAudio`. impl Decodable for SineAudio { - type Decoder = SineDecoder; - type DecoderItem = ::Item; + type Decoder = SineDecoder; + fn decoder(&self) -> Self::Decoder { SineDecoder::new(self.frequency) }