Struct dir_meta::FsWatcher

source ·
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

source

pub fn new(sender: FsSender) -> Self

Create a new FsWatcher by passing an async-channel::channel::Sender with type specified by FsSender

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);
        }
    });
}
source

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);
        }
    });
}
source

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§

source§

impl Debug for FsWatcher

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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.

§

impl<T> Instrument for T

§

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

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

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

§

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

§

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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