Skip to main content

Watch

Struct Watch 

Source
pub struct Watch { /* private fields */ }
Expand description

A watch on one content directory.

Holds the platform watcher, which stops when this is dropped.

Implementations§

Source§

impl Watch

Source

pub fn on(dir: &Path, content_name: &str) -> Result<Self>

Watch dir for changes to content_name and to anything beside it.

Non-recursive: the content directory has no subdirectories of this tool’s making, and an application that creates one has still created a sibling, which is the signal either way.

§Errors

Where the platform watcher cannot be created or cannot watch dir.

Source

pub fn drain(&self) -> impl Iterator<Item = Change> + '_

Every change that has arrived, without waiting.

Source

pub fn next_change(&self, within: Duration) -> Option<Change>

Wait up to within for the next change.

Trait Implementations§

Source§

impl Drop for Watch

The stop is waited for, and this is the fix for a measured hang.

notify’s watcher drop is fire-and-forget: it posts Action::Stop, wakes its server thread and returns, leaving that thread inside stop_watch. Whatever removes the watched directory next therefore races a watch that is still stopping, and on Windows that pair deadlocks — stop_watch waits INFINITE for a semaphore its own completion routine does not post when it re-arms ReadDirectoryChangesW, and the re-armed read does not return while a remove_dir_all is walking the same directory.

Measured 2026-09-07 before this existed: a diagnostic that drops a watch and then removes the directory wedged 9 runs in 20, one instance parked with zero CPU for over ten minutes; Opened::close, which removes first and drops after, wedged past a 300-second timeout with the same two stacks. docs/windows-save-test-hang.md has both, and the ordering alone was never the cure: the 9-in-20 case already dropped the watch first.

So the watcher goes, and then this waits for the backend to say the watch has actually stopped, which is the guarantee the caller needs before removing anything. [STOP_WAIT] bounds the wait so that a stop which never finishes is a delay rather than a second hang.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Sync for Watch

§

impl Freeze for Watch

§

impl RefUnwindSafe for Watch

§

impl Send for Watch

§

impl Unpin for Watch

§

impl UnsafeUnpin for Watch

§

impl UnwindSafe for Watch

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more