pub struct HotReload { /* private fields */ }Expand description
Poll-based hot-reload watcher.
No platform-specific file-watch APIs are used. Instead, poll() is called
periodically (e.g. every second) and compares the mtime of each watched
file against the value recorded at load time. Changed files are returned
so AssetServer can queue them for reload.
§Limitations
- mtime resolution is operating-system dependent (commonly 1 s on FAT32).
- Files inside
AssetPackarchives are not watched.
Implementations§
Source§impl HotReload
impl HotReload
Sourcepub fn new(poll_interval: Duration, enabled: bool) -> Self
pub fn new(poll_interval: Duration, enabled: bool) -> Self
Create a new watcher.
poll_interval — how often to stat files when poll() is called.
enabled — pass false in release builds to disable entirely.
Sourcepub fn watch(
&mut self,
path: PathBuf,
asset_id: u64,
current_mtime: Option<SystemTime>,
)
pub fn watch( &mut self, path: PathBuf, asset_id: u64, current_mtime: Option<SystemTime>, )
Register a file to be watched for changes.
Sourcepub fn unwatch(&mut self, asset_id: u64)
pub fn unwatch(&mut self, asset_id: u64)
Unwatch a specific asset ID. Removes the file entry if no more IDs use it.
Sourcepub fn poll(&mut self) -> Vec<(PathBuf, Vec<u64>)>
pub fn poll(&mut self) -> Vec<(PathBuf, Vec<u64>)>
Poll all watched files. Returns a list of (path, asset_ids) for every
file whose mtime has changed since the last observation.
Returns an empty list if polling is disabled or the interval hasn’t elapsed.
Sourcepub fn force_next_poll(&mut self)
pub fn force_next_poll(&mut self)
Force the next poll() call to check all files regardless of interval.
Sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Enable or disable hot-reload at runtime.
Sourcepub fn watched_count(&self) -> usize
pub fn watched_count(&self) -> usize
Number of files currently being watched.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HotReload
impl RefUnwindSafe for HotReload
impl Send for HotReload
impl Sync for HotReload
impl Unpin for HotReload
impl UnsafeUnpin for HotReload
impl UnwindSafe for HotReload
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
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.