pub struct HotReloadWatcher { /* private fields */ }Expand description
Watches asset files for changes and triggers reloads.
§Thread Safety
HotReloadWatcher is Send but NOT Sync. It should be accessed from
the main thread and used with AssetServer in the game loop.
§Example
use goud_engine::assets::{AssetServer, HotReloadWatcher, HotReloadConfig};
use std::time::Duration;
let mut server = AssetServer::new();
let config = HotReloadConfig::new()
.with_debounce(Duration::from_millis(200))
.watch_extension("png")
.watch_extension("json");
let mut watcher = HotReloadWatcher::with_config(&server, config).unwrap();
// In game loop
loop {
watcher.process_events(&mut server);
// ... render, update, etc.
}Implementations§
Source§impl HotReloadWatcher
impl HotReloadWatcher
Sourcepub fn new(server: &AssetServer) -> NotifyResult<Self>
pub fn new(server: &AssetServer) -> NotifyResult<Self>
Creates a new hot reload watcher for the given asset server.
Uses default configuration (enabled in debug builds).
§Errors
Returns an error if the file watcher cannot be initialized.
§Example
use goud_engine::assets::{AssetServer, HotReloadWatcher};
let server = AssetServer::new();
let watcher = HotReloadWatcher::new(&server).unwrap();Sourcepub fn with_config(
server: &AssetServer,
config: HotReloadConfig,
) -> NotifyResult<Self>
pub fn with_config( server: &AssetServer, config: HotReloadConfig, ) -> NotifyResult<Self>
Creates a new hot reload watcher with custom configuration.
§Errors
Returns an error if the file watcher cannot be initialized.
Sourcepub fn is_watching(&self, path: &Path) -> bool
pub fn is_watching(&self, path: &Path) -> bool
Returns whether a path is currently being watched.
Sourcepub fn watched_paths(&self) -> &HashSet<PathBuf>
pub fn watched_paths(&self) -> &HashSet<PathBuf>
Returns the set of watched paths.
Sourcepub fn config(&self) -> &HotReloadConfig
pub fn config(&self) -> &HotReloadConfig
Returns the configuration.
Sourcepub fn config_mut(&mut self) -> &mut HotReloadConfig
pub fn config_mut(&mut self) -> &mut HotReloadConfig
Returns a mutable reference to the configuration.
Note: Changing the configuration does not affect already-watched paths.
Sourcepub fn process_events(&mut self, server: &mut AssetServer) -> usize
pub fn process_events(&mut self, server: &mut AssetServer) -> usize
Processes pending file system events and reloads changed assets.
Call this once per frame in your game loop.
§Returns
The number of assets that were reloaded.
§Example
loop {
let reloaded = watcher.process_events(&mut server);
if reloaded > 0 {
println!("Reloaded {} assets", reloaded);
}
// ... rest of game loop
}Sourcepub fn clear_debounce(&mut self)
pub fn clear_debounce(&mut self)
Clears the debounce map.
Useful for testing or forcing immediate reloads.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HotReloadWatcher
impl RefUnwindSafe for HotReloadWatcher
impl Send for HotReloadWatcher
impl !Sync for HotReloadWatcher
impl Unpin for HotReloadWatcher
impl UnsafeUnpin for HotReloadWatcher
impl UnwindSafe for HotReloadWatcher
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<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more