pub struct FsWatcher { /* private fields */ }Expand description
This directory inherits most types from inotify crate
Create a watcher for a certain path that can be a file or directory
Structure
use dir_meta::FsSender;
use std::path::PathBuf;
#[derive(Debug)]
pub struct FsWatcher {
path: Option<PathBuf>,
sender: FsSender,
}Example
use dir_meta::{inotify::WatchMask, smol::channel, FsWatcher, WatcherOutcome};
smol::block_on(async {
let (sender, receiver) = channel::unbounded::<WatcherOutcome>();
let watch_options =
WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE | WatchMask::DELETE_SELF;
smol::spawn(FsWatcher::new(sender).path("Foo").watch(watch_options)).detach();
while let Ok(data) = receiver.recv().await {
dbg!(data);
}
});Implementations§
source§impl FsWatcher
impl FsWatcher
sourcepub fn new(sender: FsSender) -> Self
pub fn new(sender: FsSender) -> Self
Examples found in repository?
examples/watch_path.rs (line 11)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
smol::block_on(async {
let (sender, receiver) = channel::unbounded::<WatcherOutcome>();
let watch_options =
WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE | WatchMask::DELETE_SELF;
smol::spawn(async move {
FsWatcher::new(sender)
.path("Foo")
.watch(watch_options)
.await
.unwrap();
})
.detach();
while let Ok(data) = receiver.recv().await {
dbg!(data);
}
});
}sourcepub fn path(self, path: impl AsRef<Path>) -> Self
pub fn path(self, path: impl AsRef<Path>) -> Self
Add the path to listen to
Examples found in repository?
examples/watch_path.rs (line 12)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
smol::block_on(async {
let (sender, receiver) = channel::unbounded::<WatcherOutcome>();
let watch_options =
WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE | WatchMask::DELETE_SELF;
smol::spawn(async move {
FsWatcher::new(sender)
.path("Foo")
.watch(watch_options)
.await
.unwrap();
})
.detach();
while let Ok(data) = receiver.recv().await {
dbg!(data);
}
});
}sourcepub async fn watch(self, watch_for: WatchMask) -> Result<()>
pub async fn watch(self, watch_for: WatchMask) -> Result<()>
Watch the path using the parameters from inotify::WatchMask
which can be concatenated WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE
Examples found in repository?
examples/watch_path.rs (line 13)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
smol::block_on(async {
let (sender, receiver) = channel::unbounded::<WatcherOutcome>();
let watch_options =
WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE | WatchMask::DELETE_SELF;
smol::spawn(async move {
FsWatcher::new(sender)
.path("Foo")
.watch(watch_options)
.await
.unwrap();
})
.detach();
while let Ok(data) = receiver.recv().await {
dbg!(data);
}
});
}Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for FsWatcher
impl Send for FsWatcher
impl Sync for FsWatcher
impl Unpin for FsWatcher
impl UnwindSafe for FsWatcher
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