Skip to main content

MioDriver

Struct MioDriver 

Source
pub struct MioDriver<S = Box<dyn Handler<Event>>> { /* private fields */ }
Expand description

World resource wrapping mio::Poll and a handler slab.

S is the handler storage type. Defaults to Box<dyn Handler<mio::event::Event>>.

Users interact with this through Res<MioDriver<S>> (for registry()) or ResMut<MioDriver<S>> (for insert/remove).

Implementations§

Source§

impl<S> MioDriver<S>

Source

pub fn registry(&self) -> &Registry

Access the mio registry for registering/reregistering sources.

Poll::registry() takes &self, so this works through Res<MioDriver<S>> (shared access).

Source

pub fn insert(&mut self, handler: S) -> Token

Insert a handler and return its token.

The token maps to a mio::Token for use with Registry::register. Requires ResMut<MioDriver<S>>.

Source

pub fn remove(&mut self, token: Token) -> S

Remove a handler by token.

The caller is responsible for deregistering the mio source via registry().deregister(&mut source) if no replacement handler will be inserted. Failing to deregister is safe (stale events are skipped) but wastes kernel resources.

§Panics

Panics if the token is not present in the slab.

Source

pub fn contains(&self, token: Token) -> bool

Returns true if the token has a handler in the slab.

Source

pub fn len(&self) -> usize

Number of active handlers.

Source

pub fn is_empty(&self) -> bool

Whether the handler slab is empty.

Trait Implementations§

Source§

impl<S: Send + 'static> Resource for MioDriver<S>

Auto Trait Implementations§

§

impl<S> Freeze for MioDriver<S>

§

impl<S> RefUnwindSafe for MioDriver<S>
where S: RefUnwindSafe,

§

impl<S> Send for MioDriver<S>
where S: Send,

§

impl<S> Sync for MioDriver<S>
where S: Sync,

§

impl<S> Unpin for MioDriver<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for MioDriver<S>

§

impl<S> UnwindSafe for MioDriver<S>
where S: UnwindSafe,

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

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.