pub struct EventWatcher { /* private fields */ }Expand description
Event-driven watcher built on top of notify.
Owns the recommended backend (FSEvents/inotify/RDCW), a debounce
thread, and the receiver end of the batched-event channel. Dropping
the watcher tears down the backend and the debounce thread.
Implementations§
Source§impl EventWatcher
impl EventWatcher
Sourcepub fn new(dir: &Path) -> Result<Self, SsgError>
pub fn new(dir: &Path) -> Result<Self, SsgError>
Builds a watcher rooted at dir, watching recursively, with a
100 ms debounce window.
§Errors
Returns SsgError::Io wrapping the underlying notify::Error
when the backend cannot subscribe (missing directory, permission
denied, kernel resource exhaustion).
§Examples
use ssg::event_watch::{EventWatcher, DEFAULT_DEBOUNCE};
let tmp = tempfile::tempdir().unwrap();
let w = EventWatcher::new(tmp.path()).unwrap();
assert_eq!(w.debounce(), DEFAULT_DEBOUNCE);Sourcepub fn with_debounce(dir: &Path, debounce: Duration) -> Result<Self, SsgError>
pub fn with_debounce(dir: &Path, debounce: Duration) -> Result<Self, SsgError>
Same as Self::new but with a caller-supplied debounce window
(used by tests to keep latency low).
§Errors
See Self::new.
§Examples
use std::time::Duration;
use ssg::event_watch::EventWatcher;
let tmp = tempfile::tempdir().unwrap();
let w = EventWatcher::with_debounce(tmp.path(), Duration::from_millis(50)).unwrap();
assert_eq!(w.debounce(), Duration::from_millis(50));Sourcepub fn recv(&self) -> Option<ChangeBatch>
pub fn recv(&self) -> Option<ChangeBatch>
Blocks until the next debounced batch is available.
Returns None if the watcher is being torn down.
§Examples
use ssg::event_watch::EventWatcher;
let tmp = tempfile::tempdir().unwrap();
let w = EventWatcher::new(tmp.path()).unwrap();
// Blocks until a change arrives — would hang in a doctest sandbox.
if let Some(batch) = w.recv() {
assert!(!batch.paths.is_empty());
}Sourcepub fn recv_timeout(&self, timeout: Duration) -> RecvOutcome
pub fn recv_timeout(&self, timeout: Duration) -> RecvOutcome
Like Self::recv but with a timeout.
Returns:
RecvOutcome::Batch— a debounced batch arrived.RecvOutcome::Timeout— no batch withintimeout.RecvOutcome::Closed— the watcher was dropped or the debounce thread exited.
§Examples
use std::time::Duration;
use ssg::event_watch::{EventWatcher, RecvOutcome};
let tmp = tempfile::tempdir().unwrap();
let w = EventWatcher::with_debounce(tmp.path(), Duration::from_millis(20)).unwrap();
let out = w.recv_timeout(Duration::from_millis(30));
assert!(!out.is_closed());Sourcepub const fn debounce(&self) -> Duration
pub const fn debounce(&self) -> Duration
Debounce window in effect for this watcher.
§Examples
use std::time::Duration;
use ssg::event_watch::EventWatcher;
let tmp = tempfile::tempdir().unwrap();
let w = EventWatcher::with_debounce(tmp.path(), Duration::from_millis(75)).unwrap();
assert_eq!(w.debounce(), Duration::from_millis(75));Trait Implementations§
Source§impl Debug for EventWatcher
impl Debug for EventWatcher
Source§impl Drop for EventWatcher
impl Drop for EventWatcher
Auto Trait Implementations§
impl !Freeze for EventWatcher
impl !Sync for EventWatcher
impl RefUnwindSafe for EventWatcher
impl Send for EventWatcher
impl Unpin for EventWatcher
impl UnsafeUnpin for EventWatcher
impl UnwindSafe for EventWatcher
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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