Struct NotifySource

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

Calloop event source for watching files.

This struct implements EventSource, which allows passing it to LoopHandle::insert_source for registering it with calloop.

Since this implements Deref and DerefMut into RecommendedWatcher, you can call any function from Watcher on it. Use this to watch new files.

§Example

use std::path::Path;

use calloop::EventLoop;
use calloop_notify::NotifySource;
use calloop_notify::notify::{RecursiveMode, Watcher};

// Create calloop event loop.
let mut event_loop = EventLoop::try_new().unwrap();
let loop_handle = event_loop.handle();

// Watch current directory recursively.
let mut notify_source = NotifySource::new().unwrap();
notify_source.watch(Path::new("."), RecursiveMode::Recursive).unwrap();

// Insert notify source into calloop.
loop_handle
    .insert_source(notify_source, |event, _, _: &mut ()| {
        println!("Notify Event: {event:?}");
    })
    .unwrap();

// Dispatch event loop.
loop {
    event_loop.dispatch(None, &mut ()).unwrap();
}

Implementations§

Source§

impl NotifySource

Source

pub fn new() -> Result<Self, Error>

Create the event source.

§Errors

If the notify watcher creation failed.

§Example
use calloop_notify::NotifySource;

let notify_source = NotifySource::new().unwrap();
Examples found in repository?
examples/watch.rs (line 13)
7fn main() {
8    // Create calloop event loop.
9    let mut event_loop = EventLoop::try_new().unwrap();
10    let loop_handle = event_loop.handle();
11
12    // Watch current directory recursively.
13    let mut notify_source = NotifySource::new().unwrap();
14    notify_source.watch(Path::new("."), RecursiveMode::Recursive).unwrap();
15
16    // Insert notify source into calloop.
17    loop_handle
18        .insert_source(notify_source, |event, _, _| {
19            println!("Notify Event: {event:?}");
20        })
21        .unwrap();
22
23    // Dispatch event loop.
24    loop {
25        event_loop.dispatch(None, &mut ()).unwrap();
26    }
27}

Trait Implementations§

Source§

impl Deref for NotifySource

Source§

type Target = INotifyWatcher

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for NotifySource

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl EventSource for NotifySource

Source§

type Error = ChannelError

The error type returned from process_events() (not the user callback!).
Source§

type Event = Event

The type of events generated by your source.
Source§

type Metadata = ()

Some metadata of your event source Read more
Source§

type Ret = ()

The return type of the user callback Read more
Source§

fn process_events<F>( &mut self, readiness: Readiness, token: Token, callback: F, ) -> Result<PostAction, Self::Error>
where F: FnMut(Self::Event, &mut Self::Metadata) -> Self::Ret,

Process any relevant events Read more
Source§

fn register( &mut self, poll: &mut Poll, token_factory: &mut TokenFactory, ) -> Result<()>

Register yourself to this poll instance Read more
Source§

fn reregister( &mut self, poll: &mut Poll, token_factory: &mut TokenFactory, ) -> Result<()>

Re-register your file descriptors Read more
Source§

fn unregister(&mut self, poll: &mut Poll) -> Result<()>

Unregister your file descriptors Read more
Source§

const NEEDS_EXTRA_LIFECYCLE_EVENTS: bool = false

Whether this source needs to be sent the EventSource::before_sleep and EventSource::before_handle_events notifications. These are opt-in because they require more expensive checks, and almost all sources will not need these notifications
Source§

fn before_sleep(&mut self) -> Result<Option<(Readiness, Token)>, Error>

Notification that a single poll is about to begin Read more
Source§

fn before_handle_events(&mut self, events: EventIterator<'_>)

Notification that polling is complete, and EventSource::process_events will be called with the given events for this source. The iterator may be empty, which indicates that no events were generated for this source 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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
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