bevy/crates/bevy_render/src
Arthur Brussee ac49dce4ca
Use async-fn in traits rather than BoxedFuture (#12550)
# Objective

Simplify implementing some asset traits without Box::pin(async move{})
shenanigans.
Fixes (in part) https://github.com/bevyengine/bevy/issues/11308

## Solution
Use async-fn in traits when possible in all traits. Traits with return
position impl trait are not object safe however, and as AssetReader and
AssetWriter are both used with dynamic dispatch, you need a Boxed
version of these futures anyway.

In the future, Rust is [adding
](https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html)proc
macros to generate these traits automatically, and at some point in the
future dyn traits should 'just work'. Until then.... this seemed liked
the right approach given more ErasedXXX already exist, but, no clue if
there's plans here! Especially since these are public now, it's a bit of
an unfortunate API, and means this is a breaking change.

In theory this saves some performance when these traits are used with
static dispatch, but, seems like most code paths go through dynamic
dispatch, which boxes anyway.

I also suspect a bunch of the lifetime annotations on these function
could be simplified now as the BoxedFuture was often the only thing
returned which needed a lifetime annotation, but I'm not touching that
for now as traits + lifetimes can be so tricky.

This is a revival of
[pull/11362](https://github.com/bevyengine/bevy/pull/11362) after a
spectacular merge f*ckup, with updates to the latest Bevy. Just to recap
some discussion:
- Overall this seems like a win for code quality, especially when
implementing these traits, but a loss for having to deal with ErasedXXX
variants.
- `ConditionalSend` was the preferred name for the trait that might be
Send, to deal with wasm platforms.
- When reviewing be sure to disable whitespace difference, as that's 95%
of the PR.


## Changelog
- AssetReader, AssetWriter, AssetLoader, AssetSaver and Process now use
async-fn in traits rather than boxed futures.

## Migration Guide
- Custom implementations of AssetReader, AssetWriter, AssetLoader,
AssetSaver and Process should switch to async fn rather than returning a
bevy_utils::BoxedFuture.
- Simultaniously, to use dynamic dispatch on these traits you should
instead use dyn ErasedXXX.
2024-03-18 17:56:57 +00:00
..
batching Disentangle bevy_utils/bevy_core's reexported dependencies (#12313) 2024-03-07 02:30:15 +00:00
camera Clean up type registrations (#12314) 2024-03-06 16:05:53 +00:00
diagnostic Add pipeline statistics (#9135) 2024-03-17 20:29:35 +00:00
mesh change doc for SphereKind::Ico to reflect that the triangles are equa… (#12482) 2024-03-15 03:32:52 +00:00
primitives Move EntityHash related types into bevy_ecs (#11498) 2024-02-12 15:02:24 +00:00
render_graph Replace bevy_log's tracing reexport with bevy_utils' (#12254) 2024-03-02 18:38:04 +00:00
render_phase Add pipeline statistics (#9135) 2024-03-17 20:29:35 +00:00
render_resource Use async-fn in traits rather than BoxedFuture (#12550) 2024-03-18 17:56:57 +00:00
renderer Add pipeline statistics (#9135) 2024-03-17 20:29:35 +00:00
texture Use async-fn in traits rather than BoxedFuture (#12550) 2024-03-18 17:56:57 +00:00
view move ci testing to dev_tools (#12371) 2024-03-07 22:38:21 +00:00
alpha.rs Move AlphaMode into bevy_render (#12012) 2024-02-21 19:34:10 +00:00
deterministic.rs Option to enable deterministic rendering (#11248) 2024-01-09 00:46:01 +00:00
extract_component.rs Revert rendering-related associated type name changes (#11027) 2024-01-22 15:01:55 +00:00
extract_instances.rs Move EntityHash related types into bevy_ecs (#11498) 2024-02-12 15:02:24 +00:00
extract_param.rs Enable the unsafe_op_in_unsafe_fn lint (#11591) 2024-01-28 23:18:11 +00:00
extract_resource.rs Replace bevy_log's tracing reexport with bevy_utils' (#12254) 2024-03-02 18:38:04 +00:00
globals.rs Update to wgpu 0.19 and raw-window-handle 0.6 (#11280) 2024-01-26 18:14:21 +00:00
globals.wgsl Refactor Globals and View structs into separate shaders (#7512) 2023-02-11 17:55:18 +00:00
gpu_component_array_buffer.rs Reorder render sets, refactor bevy_sprite to take advantage (#9236) 2023-08-27 14:33:49 +00:00
lib.rs Add pipeline statistics (#9135) 2024-03-17 20:29:35 +00:00
maths.wgsl Add support for KHR_texture_transform (#11904) 2024-02-21 01:11:28 +00:00
pipelined_rendering.rs Simplified backtraces (#12305) 2024-03-10 12:18:59 +00:00
render_asset.rs stop retrying removed assets (#12505) 2024-03-16 04:49:16 +00:00
settings.rs Update to wgpu 0.19 and raw-window-handle 0.6 (#11280) 2024-01-26 18:14:21 +00:00
spatial_bundle.rs Implement Clone for VisibilityBundle and SpatialBundle (#10394) 2023-11-07 21:25:00 +00:00