[−][src]Trait calloop::EventSource
Trait representing a source that can be inserted into an EventLoop
This is the interface between the source and the loop, you need to implement it to use your custom event sources.
Two kind of event sources are possible, OS-based, or purely userspace.
OS-based event sources rely on some ressource that is managed by the OS and for which it can signal readiness (a socket par example).
Purely userspace event sources are not, and need to manually signal
readiness to the event queue via a Waker
.
The distinction between the two kind is made depending on the return
value of the implementation of the as_mio_source
method. The
default implementation returns None
, meaning that the source is
purely userspace. If your source is OS-based, you need to provide the
necessary mio
glue as a return value.
See EventDispatcher
for details about
how both kind of sources are dispatched.
Associated Types
type Event
The type of events generated by your sources
Required methods
fn make_dispatcher<Data: 'static, F: FnMut(Self::Event, &mut Data) + 'static>(
&mut self,
callback: F,
waker: &Arc<Waker>
) -> Rc<RefCell<dyn EventDispatcher<Data>>>
&mut self,
callback: F,
waker: &Arc<Waker>
) -> Rc<RefCell<dyn EventDispatcher<Data>>>
Build an EventDispatcher
for this event source
Your dispatcher is responsible for converting the basic
readiness information into your Event
type, and forwarding
it to the callback.
For example, a wrapper around a socket may read & parse a message and provide the parsed message to the callback.
If your source is userspace and require some initialization, this is the place to do it. You are provided a waker that you'll need to use to signal the event loop for readiness. OS-based sources should ignore it.
See EventDispatcher
for details about
how dispatching occurs.
Provided methods
fn as_mio_source(&mut self) -> Option<&mut dyn MioSource>
Access the mio
-aware resource for this source
This type is what will be forwarded to the underlying mio::Poll
for registration.
If you are implementing the EventSource
trait for a type
that already implement mio::event::Source
, the implementation
of this method can be as simple as the following:
fn as_mio_source(&mut self) -> Option<&mut dyn MioSource> { Some(self) }
fn interest(&self) -> Interest
The requested interest for OS-based sources
This method is ignored for purely userspace event sources.
Implementors
impl EventSource for Signals
[src]
type Event = Event
fn interest(&self) -> Interest
[src]
fn as_mio_source(&mut self) -> Option<&mut dyn MioSource>
[src]
fn make_dispatcher<Data: 'static, F: FnMut(Event, &mut Data) + 'static>(
&mut self,
callback: F,
_: &Arc<Waker>
) -> Rc<RefCell<dyn EventDispatcher<Data>>>
[src]
&mut self,
callback: F,
_: &Arc<Waker>
) -> Rc<RefCell<dyn EventDispatcher<Data>>>
impl<E: MioSource + 'static> EventSource for Generic<E>
[src]
type Event = Event<E>
fn interest(&self) -> Interest
[src]
fn as_mio_source(&mut self) -> Option<&mut dyn MioSource>
[src]
fn make_dispatcher<Data: 'static, F: FnMut(Event<E>, &mut Data) + 'static>(
&mut self,
callback: F,
_: &Arc<Waker>
) -> Rc<RefCell<dyn EventDispatcher<Data>>>
[src]
&mut self,
callback: F,
_: &Arc<Waker>
) -> Rc<RefCell<dyn EventDispatcher<Data>>>
impl<T: 'static> EventSource for Channel<T>
[src]
type Event = Event<T>
fn make_dispatcher<Data: 'static, F: FnMut(Event<T>, &mut Data) + 'static>(
&mut self,
callback: F,
waker: &Arc<Waker>
) -> Rc<RefCell<dyn EventDispatcher<Data>>>
[src]
&mut self,
callback: F,
waker: &Arc<Waker>
) -> Rc<RefCell<dyn EventDispatcher<Data>>>
impl<T: 'static> EventSource for Timer<T>
[src]
type Event = (T, TimerHandle<T>)
fn interest(&self) -> Interest
[src]
fn as_mio_source(&mut self) -> Option<&mut dyn MioSource>
[src]
fn make_dispatcher<Data: 'static, F: FnMut((T, TimerHandle<T>), &mut Data) + 'static>(
&mut self,
callback: F,
waker: &Arc<Waker>
) -> Rc<RefCell<dyn EventDispatcher<Data>>>
[src]
&mut self,
callback: F,
waker: &Arc<Waker>
) -> Rc<RefCell<dyn EventDispatcher<Data>>>