pub trait AssetIo: Downcast + Send + Sync + 'static {
    // Required methods
    fn load_path<'a>(
        &'a self,
        path: &'a Path
    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8, Global>, AssetIoError>> + Send + 'a, Global>>;
    fn read_directory(
        &self,
        path: &Path
    ) -> Result<Box<dyn Iterator<Item = PathBuf> + 'static, Global>, AssetIoError>;
    fn get_metadata(&self, path: &Path) -> Result<Metadata, AssetIoError>;
    fn watch_path_for_changes(
        &self,
        to_watch: &Path,
        to_reload: Option<PathBuf>
    ) -> Result<(), AssetIoError>;
    fn watch_for_changes(&self) -> Result<(), AssetIoError>;

    // Provided methods
    fn is_dir(&self, path: &Path) -> bool { ... }
    fn is_file(&self, path: &Path) -> bool { ... }
}
Expand description

A storage provider for an AssetServer.

An asset I/O is the backend actually providing data for the asset loaders managed by the asset server. An average user will probably be just fine with the default [FileAssetIo], but you can easily use your own custom I/O to, for example, load assets from cloud storage or create a seamless VFS layout using custom containers.

See the custom_asset_io example in the repository for more details.

Required Methods§

fn load_path<'a>( &'a self, path: &'a Path ) -> Pin<Box<dyn Future<Output = Result<Vec<u8, Global>, AssetIoError>> + Send + 'a, Global>>

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

fn read_directory( &self, path: &Path ) -> Result<Box<dyn Iterator<Item = PathBuf> + 'static, Global>, AssetIoError>

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

fn get_metadata(&self, path: &Path) -> Result<Metadata, AssetIoError>

Returns metadata about the filesystem entry at the provided path.

fn watch_path_for_changes( &self, to_watch: &Path, to_reload: Option<PathBuf> ) -> Result<(), AssetIoError>

Tells the asset I/O to watch for changes recursively at the provided path.

No-op if watch_for_changes hasn’t been called yet. Otherwise triggers a reload each time to_watch changes. In most cases the asset found at the watched path should be changed, but when an asset depends on data at another path, the asset’s path is provided in to_reload. Note that there may be a many-to-many correspondence between to_watch and to_reload paths.

fn watch_for_changes(&self) -> Result<(), AssetIoError>

Enables change tracking in this asset I/O.

Provided Methods§

fn is_dir(&self, path: &Path) -> bool

Returns true if the path is a directory.

fn is_file(&self, path: &Path) -> bool

Returns true if the path is a file.

Implementations§

§

impl dyn AssetIo + 'static

pub fn is<__T>(&self) -> boolwhere __T: AssetIo,

Returns true if the trait object wraps an object of type __T.

pub fn downcast<__T>( self: Box<dyn AssetIo + 'static, Global> ) -> Result<Box<__T, Global>, Box<dyn AssetIo + 'static, Global>>where __T: AssetIo,

Returns a boxed object from a boxed trait object if the underlying object is of type __T. Returns the original boxed trait if it isn’t.

pub fn downcast_rc<__T>( self: Rc<dyn AssetIo + 'static> ) -> Result<Rc<__T>, Rc<dyn AssetIo + 'static>>where __T: AssetIo,

Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of type __T. Returns the original Rc-ed trait if it isn’t.

pub fn downcast_ref<__T>(&self) -> Option<&__T>where __T: AssetIo,

Returns a reference to the object within the trait object if it is of type __T, or None if it isn’t.

pub fn downcast_mut<__T>(&mut self) -> Option<&mut __T>where __T: AssetIo,

Returns a mutable reference to the object within the trait object if it is of type __T, or None if it isn’t.

Implementors§

source§

impl AssetIo for BundledAssetIo

§

impl AssetIo for FileAssetIo