bevy/examples/3d
Benjamin Brienen 93fc2d12cf
Remove incorrect equality comparisons for asset load error types (#15890)
# Objective

The type `AssetLoadError` has `PartialEq` and `Eq` impls, which is
problematic due to the fact that the `AssetLoaderError` and
`AddAsyncError` variants lie in their impls: they will return `true` for
any `Box<dyn Error>` with the same `TypeId`, even if the actual value is
different. This can lead to subtle bugs if a user relies on the equality
comparison to ensure that two values are equal.

The same is true for `DependencyLoadState`,
`RecursiveDependencyLoadState`.

More generally, it is an anti-pattern for large error types involving
dynamic dispatch, such as `AssetLoadError`, to have equality
comparisons. Directly comparing two errors for equality is usually not
desired -- if some logic needs to branch based on the value of an error,
it is usually more correct to check for specific variants and inspect
their fields.

As far as I can tell, the only reason these errors have equality
comparisons is because the `LoadState` enum wraps `AssetLoadError` for
its `Failed` variant. This equality comparison is only used to check for
`== LoadState::Loaded`, which we can easily replace with an `is_loaded`
method.

## Solution

Remove the `{Partial}Eq` impls from `LoadState`, which also allows us to
remove it from the error types.

## Migration Guide

The types `bevy_asset::AssetLoadError` and `bevy_asset::LoadState` no
longer support equality comparisons. If you need to check for an asset's
load state, consider checking for a specific variant using
`LoadState::is_loaded` or the `matches!` macro. Similarly, consider
using the `matches!` macro to check for specific variants of the
`AssetLoadError` type if you need to inspect the value of an asset load
error in your code.

`DependencyLoadState` and `RecursiveDependencyLoadState` are not
released yet, so no migration needed,

---------

Co-authored-by: Joseph <21144246+JoJoJet@users.noreply.github.com>
2024-10-14 01:00:45 +00:00
..
3d_scene.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
3d_shapes.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
3d_viewport_to_world.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
animated_material.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
anisotropy.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
anti_aliasing.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
atmospheric_fog.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
auto_exposure.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
blend_modes.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
bloom_3d.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
camera_sub_view.rs improve sub view example with dynamic viewports (#15681) 2024-10-08 16:07:31 +00:00
clearcoat.rs Remove the Component trait implementation from Handle (#15796) 2024-10-09 21:10:01 +00:00
color_grading.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
deferred_rendering.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
depth_of_field.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
fog.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
fog_volumes.rs Deprecate SpatialBundle (#15830) 2024-10-13 17:28:22 +00:00
generate_custom_mesh.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
irradiance_volumes.rs Deprecate SpatialBundle (#15830) 2024-10-13 17:28:22 +00:00
lighting.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
lightmaps.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
lines.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
load_gltf.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
load_gltf_extras.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
mesh_ray_cast.rs Add mesh picking backend and MeshRayCast system parameter (#15800) 2024-10-13 17:24:19 +00:00
meshlet.rs Remove the Component trait implementation from Handle (#15796) 2024-10-09 21:10:01 +00:00
motion_blur.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
order_independent_transparency.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
orthographic.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
parallax_mapping.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
parenting.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
pbr.rs Remove incorrect equality comparisons for asset load error types (#15890) 2024-10-14 01:00:45 +00:00
pcss.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
post_processing.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
query_gltf_primitives.rs Fix query_gltf_primitives example (#15715) 2024-10-07 23:03:16 +00:00
reflection_probes.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
render_to_texture.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
rotate_environment_map.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
scrolling_fog.rs Deprecate SpatialBundle (#15830) 2024-10-13 17:28:22 +00:00
shadow_biases.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
shadow_caster_receiver.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
skybox.rs Remove incorrect equality comparisons for asset load error types (#15890) 2024-10-14 01:00:45 +00:00
spherical_area_lights.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
split_screen.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
spotlight.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
ssao.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
ssr.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
texture.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
tonemapping.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
transmission.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
transparency_3d.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
two_passes.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
update_gltf_scene.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
vertex_colors.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
visibility_range.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
volumetric_fog.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
wireframe.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00