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
impl MountWatcher
Sourcepub fn new(
callback: impl FnMut(MountEvent) -> WatchControl + Send + 'static,
) -> Result<Self, SetupError>
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MountWatcher
impl !RefUnwindSafe for MountWatcher
impl Send for MountWatcher
impl Sync for MountWatcher
impl Unpin for MountWatcher
impl !UnwindSafe for MountWatcher
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
Mutably borrows from an owned value. Read more