Skip to main content

BundledAssets

Trait BundledAssets 

Source
pub trait BundledAssets: Send + Sync {
    // Required method
    fn read(&self, path: &str) -> Result<Vec<u8>, BundledAssetError>;

    // Provided methods
    fn open(
        &self,
        path: &str,
    ) -> Result<Box<dyn BundledAssetReader>, BundledAssetError> { ... }
    fn len(&self, path: &str) -> Option<u64> { ... }
}
Expand description

Access to files packaged in the app bundle.

Reads are synchronous, which is what a packaged file on a native platform is: Android’s asset manager, an application bundle and a directory beside the executable all answer without waiting on a network. A browser has no such file — its resources arrive over HTTP — so the web registers no backend and bundled_assets answers None there. An application that ships resources to the web fetches them through crate::http, which is async because that is what the medium is.

Required Methods§

Source

fn read(&self, path: &str) -> Result<Vec<u8>, BundledAssetError>

Reads one bundle-relative asset in full.

Use open for anything that should not be held in memory all at once — a bundled model, a video, a database seed.

Provided Methods§

Source

fn open( &self, path: &str, ) -> Result<Box<dyn BundledAssetReader>, BundledAssetError>

Opens one bundle-relative asset for chunked reading.

The default reads the whole asset and hands it back a chunk at a time, which is honest for a backend that can only produce the bytes at once. Backends with a real streaming API — Android’s AssetManager, a file in an application bundle — override it and never materialise the asset.

Source

fn len(&self, path: &str) -> Option<u64>

The asset’s byte length without reading it, when the backend knows it.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§