Trait bevy_asset::AssetIo

source ·
pub trait AssetIo: Downcast + Send + Sync + 'static {
    // Required methods
    fn load_path<'a>(
        &'a self,
        path: &'a Path
    ) -> BoxedFuture<'a, Result<Vec<u8>, AssetIoError>>;
    fn read_directory(
        &self,
        path: &Path
    ) -> Result<Box<dyn Iterator<Item = PathBuf>>, 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§

source

fn load_path<'a>( &'a self, path: &'a Path ) -> BoxedFuture<'a, Result<Vec<u8>, AssetIoError>>

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

source

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

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

source

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

Returns metadata about the filesystem entry at the provided path.

source

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.

source

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

Enables change tracking in this asset I/O.

Provided Methods§

source

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

Returns true if the path is a directory.

source

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

Returns true if the path is a file.

Implementations§

source§

impl dyn AssetIo

source

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

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

source

pub fn downcast<__T: AssetIo>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>

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.

source

pub fn downcast_rc<__T: AssetIo>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>

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.

source

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

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

source

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

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

Implementors§