pub struct FileWatcher { /* private fields */ }Expand description
File watcher wrapper around notify crate
Wraps notify::RecommendedWatcher with debouncing and filtering
for .dampen files. Provides a channel-based API for receiving
file change events.
Implementations§
Source§impl FileWatcher
impl FileWatcher
Sourcepub fn new(config: FileWatcherConfig) -> Result<Self, FileWatcherError>
pub fn new(config: FileWatcherConfig) -> Result<Self, FileWatcherError>
Create a new file watcher with the given configuration
Sets up a debounced file watcher with crossbeam channels for
event communication. The watcher is created but not yet watching
any paths - use watch() to add paths.
§Arguments
config- File watcher configuration
§Returns
A new FileWatcher instance or an error if watcher creation fails
§Errors
Returns an error if:
- The file watcher cannot be initialized (OS limitations, permissions)
- The debouncer setup fails
§Example
use dampen_dev::watcher::{FileWatcher, FileWatcherConfig};
let config = FileWatcherConfig::default();
let watcher = FileWatcher::new(config).expect("Failed to create watcher");Sourcepub fn watch(&mut self, path: PathBuf) -> Result<(), FileWatcherError>
pub fn watch(&mut self, path: PathBuf) -> Result<(), FileWatcherError>
Add a path to watch for changes
Watches the specified path for file system changes. If the path is a directory
and recursive is enabled in the config, watches all subdirectories as well.
§Arguments
path- Path to watch (file or directory)
§Errors
Returns an error if:
- The path does not exist
- Permission denied to watch the path
- The path is already being watched
- OS-specific watcher limitations reached
§Example
use dampen_dev::watcher::{FileWatcher, FileWatcherConfig};
use std::path::PathBuf;
let mut watcher = FileWatcher::new(FileWatcherConfig::default()).unwrap();
watcher.watch(PathBuf::from("src/ui")).expect("Failed to watch path");Sourcepub fn unwatch(&mut self, path: PathBuf) -> Result<(), FileWatcherError>
pub fn unwatch(&mut self, path: PathBuf) -> Result<(), FileWatcherError>
Remove a path from the watch list
Stops watching the specified path for changes.
§Arguments
path- Path to unwatch
§Errors
Returns an error if the path is not currently being watched
§Example
use dampen_dev::watcher::{FileWatcher, FileWatcherConfig};
use std::path::PathBuf;
let mut watcher = FileWatcher::new(FileWatcherConfig::default()).unwrap();
let path = PathBuf::from("src/ui");
watcher.watch(path.clone()).unwrap();
watcher.unwatch(path).expect("Failed to unwatch path");Sourcepub fn receiver(&self) -> &Receiver<PathBuf>
pub fn receiver(&self) -> &Receiver<PathBuf>
Get the receiver for file change events
Returns a reference to the channel receiver that will receive
paths of changed .dampen files. Events are debounced according
to the configuration.
§Returns
A reference to the crossbeam channel receiver
§Example
use dampen_dev::watcher::{FileWatcher, FileWatcherConfig};
let watcher = FileWatcher::new(FileWatcherConfig::default()).unwrap();
let receiver = watcher.receiver();
// In an event loop:
// for changed_file in receiver.try_iter() {
// println!("File changed: {:?}", changed_file);
// }Sourcepub fn config(&self) -> &FileWatcherConfig
pub fn config(&self) -> &FileWatcherConfig
Auto Trait Implementations§
impl Freeze for FileWatcher
impl !RefUnwindSafe for FileWatcher
impl Send for FileWatcher
impl Sync for FileWatcher
impl Unpin for FileWatcher
impl !UnwindSafe for FileWatcher
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Application.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