bevy_asset::io

Trait AssetReader

Source
pub trait AssetReader:
    Send
    + Sync
    + 'static {
    // Required methods
    fn read<'a>(
        &'a self,
        path: &'a Path,
    ) -> impl AssetReaderFuture<Value: Reader + 'a>;
    fn read_meta<'a>(
        &'a self,
        path: &'a Path,
    ) -> impl AssetReaderFuture<Value: Reader + 'a>;
    fn read_directory<'a>(
        &'a self,
        path: &'a Path,
    ) -> impl ConditionalSendFuture<Output = Result<Box<PathStream>, AssetReaderError>>;
    fn is_directory<'a>(
        &'a self,
        path: &'a Path,
    ) -> impl ConditionalSendFuture<Output = Result<bool, AssetReaderError>>;

    // Provided method
    fn read_meta_bytes<'a>(
        &'a self,
        path: &'a Path,
    ) -> impl ConditionalSendFuture<Output = Result<Vec<u8>, AssetReaderError>> { ... }
}
Expand description

Performs read operations on an asset storage. AssetReader exposes a “virtual filesystem” API, where asset bytes and asset metadata bytes are both stored and accessible for a given path. This trait is not object safe, if needed use a dyn ErasedAssetReader instead.

This trait defines asset-agnostic mechanisms to read bytes from a storage system. For the per-asset-type saving/loading logic, see AssetSaver and AssetLoader.

For a complementary version of this trait that can write assets to storage, see AssetWriter.

Required Methods§

Source

fn read<'a>( &'a self, path: &'a Path, ) -> impl AssetReaderFuture<Value: Reader + 'a>

Returns a future to load the full file data at the provided path.

§Note for implementors

The preferred style for implementing this method is an async fn returning an opaque type.

impl AssetReader for MyReader {
    async fn read<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
        // ...
    }
}
Source

fn read_meta<'a>( &'a self, path: &'a Path, ) -> impl AssetReaderFuture<Value: Reader + 'a>

Returns a future to load the full file data at the provided path.

Source

fn read_directory<'a>( &'a self, path: &'a Path, ) -> impl ConditionalSendFuture<Output = Result<Box<PathStream>, AssetReaderError>>

Returns an iterator of directory entry names at the provided path.

Source

fn is_directory<'a>( &'a self, path: &'a Path, ) -> impl ConditionalSendFuture<Output = Result<bool, AssetReaderError>>

Returns true if the provided path points to a directory.

Provided Methods§

Source

fn read_meta_bytes<'a>( &'a self, path: &'a Path, ) -> impl ConditionalSendFuture<Output = Result<Vec<u8>, AssetReaderError>>

Reads asset metadata bytes at the given path into a Vec<u8>. This is a convenience function that wraps AssetReader::read_meta by default.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl AssetReader for FileAssetReader

Available on non-crate feature multi_threaded and non-WebAssembly only.
Source§

impl AssetReader for MemoryAssetReader

Source§

impl AssetReader for ProcessorGatedReader

Source§

impl<R: AssetReader> AssetReader for GatedReader<R>