Struct calloop::EventLoop

source ·
pub struct EventLoop<'l, Data> { /* private fields */ }
Expand description

An event loop

This loop can host several event sources, that can be dynamically added or removed.

Implementations§

source§

impl<'l, Data> EventLoop<'l, Data>

source

pub fn try_new() -> Result<Self>

Create a new event loop

Fails if the initialization of the polling system failed.

source

pub fn handle(&self) -> LoopHandle<'l, Data>

Retrieve a loop handle

source

pub fn dispatch<D: Into<Option<Duration>>>( &mut self, timeout: D, data: &mut Data ) -> Result<()>

Dispatch pending events to their callbacks

If some sources have events available, their callbacks will be immediatly called. Otherwise this will wait until an event is receive or the provided timeout is reached. If timeout is None, it will wait without a duration limit.

Once pending events have been processed or the timeout is reached, all pending idle callbacks will be fired before this method returns.

source

pub fn get_signal(&self) -> LoopSignal

Get a signal to stop this event loop from running

To be used in conjunction with the run() method.

source

pub fn run<F, D: Into<Option<Duration>>>( &mut self, timeout: D, data: &mut Data, cb: F ) -> Result<()>
where F: FnMut(&mut Data),

Run this event loop

This will repeatedly try to dispatch events (see the dispatch() method) on this event loop, waiting at most timeout every time.

Between each dispatch wait, your provided callback will be called.

You can use the get_signal() method to retrieve a way to stop or wakeup the event loop from anywhere.

Trait Implementations§

source§

impl<'l, Data> AsFd for EventLoop<'l, Data>

source§

fn as_fd(&self) -> BorrowedFd<'_>

Get the underlying fd of the poller.

This could be used to create Generic source out of the current loop and inserting into some other EventLoop.

source§

impl<'l, Data> AsRawFd for EventLoop<'l, Data>

source§

fn as_raw_fd(&self) -> RawFd

Get the underlying raw-fd of the poller.

This could be used to create Generic source out of the current loop and inserting into some other EventLoop. It’s recommended to clone fd before doing so.

source§

impl<'l, Data> Debug for EventLoop<'l, Data>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'l, Data> !RefUnwindSafe for EventLoop<'l, Data>

§

impl<'l, Data> !Send for EventLoop<'l, Data>

§

impl<'l, Data> !Sync for EventLoop<'l, Data>

§

impl<'l, Data> Unpin for EventLoop<'l, Data>

§

impl<'l, Data> !UnwindSafe for EventLoop<'l, Data>

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> AsSource for T
where T: AsFd,

source§

fn source(&self) -> BorrowedFd<'_>

Returns the borrowed file descriptor.
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<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.
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