MountWatcher

Struct MountWatcher 

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

MountWatcher allows to react to changes in the mounted filesystems.

§Stopping

When the MountWatcher is dropped, the background thread that drives the watcher is stopped, and the callback will never be called again. You can also call stop.

Furthermore, you can stop the watcher from the event handler itself, by returning WatchControl::Stop.

§Example (stop in handler)

use mount_watcher::{MountWatcher, WatchControl};

let watch = MountWatcher::new(|event| {
    let added_mounts = event.mounted;
    let removed_mounts = event.unmounted;
    let stop_condition = todo!();
    if stop_condition {
        // I have found what I wanted, stop here.
        WatchControl::Stop
    } else {
        // Continue to watch, I still want events.
        WatchControl::Continue
    }
}).unwrap();
// Wait for the watcher to be stopped by the handler
watch.join().unwrap();

Implementations§

Source§

impl MountWatcher

Source

pub fn new( callback: impl FnMut(MountEvent) -> WatchControl + Send + 'static, ) -> Result<Self, SetupError>

Watches the list of mounted filesystems and executes the callback when it changes.

Source

pub fn stop(&self) -> Result<(), StopError>

Requests the background thread to terminate.

To wait for the termination, use join.

Source

pub fn join(self) -> Result<()>

Waits for the background thread to terminate.

This blocks the current thread.

§Errors

If the background thread has panicked, an error is returned with the panic payload.

Trait Implementations§

Source§

impl Drop for MountWatcher

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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, 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.