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
impl NotifySource
Sourcepub fn new() -> Result<Self, Error>
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
impl Deref for NotifySource
Source§impl DerefMut for NotifySource
impl DerefMut for NotifySource
Source§impl EventSource for NotifySource
impl EventSource for NotifySource
Source§type Error = ChannelError
type Error = ChannelError
The error type returned from
process_events()
(not the user callback!).Source§fn process_events<F>(
&mut self,
readiness: Readiness,
token: Token,
callback: F,
) -> Result<PostAction, Self::Error>
fn process_events<F>( &mut self, readiness: Readiness, token: Token, callback: F, ) -> Result<PostAction, Self::Error>
Process any relevant events Read more
Source§fn register(
&mut self,
poll: &mut Poll,
token_factory: &mut TokenFactory,
) -> Result<()>
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<()>
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<()>
fn unregister(&mut self, poll: &mut Poll) -> Result<()>
Unregister your file descriptors Read more
Source§const NEEDS_EXTRA_LIFECYCLE_EVENTS: bool = false
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 notificationsSource§fn before_sleep(&mut self) -> Result<Option<(Readiness, Token)>, Error>
fn before_sleep(&mut self) -> Result<Option<(Readiness, Token)>, Error>
Notification that a single
poll
is about to begin Read moreSource§fn before_handle_events(&mut self, events: EventIterator<'_>)
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 moreAuto Trait Implementations§
impl Freeze for NotifySource
impl RefUnwindSafe for NotifySource
impl Send for NotifySource
impl !Sync for NotifySource
impl Unpin for NotifySource
impl UnwindSafe for NotifySource
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