pub struct Assets { /* private fields */ }Implementations§
Source§impl Assets
impl Assets
Sourcepub fn new(root: impl AsRef<Path>) -> Result<Assets, Error>
pub fn new(root: impl AsRef<Path>) -> Result<Assets, Error>
Create with root as the asset directory. Path is canonicalized eagerly to make
matching against notify events deterministic. On the web, root is a URL path
relative to the page and is used as-is.
Sourcepub fn set_web_preload<I, S>(&mut self, paths: I)
pub fn set_web_preload<I, S>(&mut self, paths: I)
Natively, in debug builds: check reads against paths instead of manifest.txt, for a
game that sets AppConfig::web_preload. No-op in release builds and on the web.
Sourcepub fn check_web_listed(&self, rel: impl AsRef<Path>)
pub fn check_web_listed(&self, rel: impl AsRef<Path>)
Natively, in debug builds: warn (once per file) if rel isn’t in the web preload list,
i.e. loading it would fail in the browser. Assets::read does this itself; call it
when reading an asset some other way, e.g. by path. Does nothing when there is no
list (no manifest.txt), for in-memory files, in release builds and on the web.
pub fn root(&self) -> &Path
pub fn resolve(&self, rel: impl AsRef<Path>) -> PathBuf
Sourcepub fn read(&self, rel: impl AsRef<Path>) -> Result<Vec<u8>, Error>
pub fn read(&self, rel: impl AsRef<Path>) -> Result<Vec<u8>, Error>
Read an asset’s bytes: from memory if it was inserted or preloaded, otherwise from disk (native only).
Sourcepub fn insert(&mut self, rel: impl AsRef<Path>, bytes: impl Into<Vec<u8>>)
pub fn insert(&mut self, rel: impl AsRef<Path>, bytes: impl Into<Vec<u8>>)
Store bytes under rel, shadowing any file at that path.
Sourcepub fn is_loaded(&self, rel: impl AsRef<Path>) -> bool
pub fn is_loaded(&self, rel: impl AsRef<Path>) -> bool
Whether rel is available in memory (inserted or preloaded).
Sourcepub fn watch(&mut self) -> Result<(), Error>
pub fn watch(&mut self) -> Result<(), Error>
Start watching the asset root recursively. Idempotent. On the web this logs that
hot-reload is unavailable and returns Ok.
Sourcepub fn drain_changes(&mut self) -> Vec<PathBuf>
pub fn drain_changes(&mut self) -> Vec<PathBuf>
Drain all queued filesystem changes since last call. Paths are canonicalized when possible. Idempotent across re-saves within one frame (HashSet-deduped). Always empty on the web.
Auto Trait Implementations§
impl !Freeze for Assets
impl !Sync for Assets
impl RefUnwindSafe for Assets
impl Send for Assets
impl Unpin for Assets
impl UnsafeUnpin for Assets
impl UnwindSafe for Assets
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.