bevy/crates/bevy_asset/src
Ludwig DUBOS 611ba8b98e
Add AsyncSeekForwardExt trait to allows a similar API to the previous Bevy version (#16027)
# Objective

This PR introduces an `AsyncSeekForwardExt` trait, which I forgot in my
previous PR #14194.

This new trait is analogous to `AsyncSeekExt` and allows all
implementors of `AsyncSeekForward` to directly use the `seek_forward`
function in async contexts.

## Solution

- Implement a new `AsyncSeekForwardExt` trait
- Automatically implement this trait for all types that implement
`AsyncSeekForward`

## Showcase

This new trait allows a similar API to the previous Bevy version:

```rust
#[derive(Default)]
struct UniverseLoader;

#[derive(Asset, TypePath, Debug)]
struct JustALilAsteroid([u8; 128]);

impl AssetLoader for UniverseLoader {
    type Asset = JustALilAsteroid;
    type Settings = ();
    type Error = std::io::Error;

    async fn load<'a>(
        &'a self,
        reader: &'a mut Reader<'a>,
        _settings: &'a Self::Settings,
        _context: &'a mut LoadContext<'_>,
    ) -> Result<Self::Asset, Self::Error> {
        // read the asteroids entry table
        let entry_offset: u64 = /* ... */;
        let current_offset: u64 = reader.seek_forward(0).await?;

        // jump to the entry
        reader.seek_forward(entry_offset - current_offset).await?;

        let mut asteroid_buf = [0; 128];
        reader.read_exact(&mut asteroid_buf).await?;

        Ok(JustALilAsteroid(asteroid_buf))
    }
    
    fn extensions(&self) -> &[&str] {
        &["celestial"]
    }
}
```
2024-10-25 20:08:14 +00:00
..
io Add AsyncSeekForwardExt trait to allows a similar API to the previous Bevy version (#16027) 2024-10-25 20:08:14 +00:00
processor Use en-us locale for typos (#16037) 2024-10-20 18:55:17 +00:00
server Use en-us locale for typos (#16037) 2024-10-20 18:55:17 +00:00
assets.rs Remove thiserror from bevy_asset (#15778) 2024-10-09 14:30:46 +00:00
direct_access_ext.rs Add methods to directly load assets from World (#12023) 2024-02-27 00:28:26 +00:00
event.rs fix: add reflect to SceneInstanceReady and other observers/events (#16018) 2024-10-20 13:51:41 +00:00
folder.rs Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
handle.rs Remove the Component trait implementation from Handle (#15796) 2024-10-09 21:10:01 +00:00
id.rs Remove thiserror from bevy_asset (#15778) 2024-10-09 14:30:46 +00:00
lib.rs Remove incorrect equality comparisons for asset load error types (#15890) 2024-10-14 01:00:45 +00:00
loader_builders.rs bevy_asset: Improve NestedLoader API (#15509) 2024-10-01 14:14:04 +00:00
loader.rs Remove thiserror from bevy_asset (#15778) 2024-10-09 14:30:46 +00:00
meta.rs Cleanup unneeded lifetimes in bevy_asset (#15546) 2024-09-30 21:54:59 +00:00
path.rs Remove thiserror from bevy_asset (#15778) 2024-10-09 14:30:46 +00:00
reflect.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
render_asset.rs Split off bevy_image from bevy_render (#15650) 2024-10-04 20:16:47 +00:00
saver.rs Cleanup unneeded lifetimes in bevy_asset (#15546) 2024-09-30 21:54:59 +00:00
transformer.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00