Struct mio::event::Events

source ·
pub struct Events { /* private fields */ }
Expand description

A collection of readiness events.

Events is passed as an argument to Poll::poll and will be used to receive any new readiness events received since the last poll. Usually, a single Events instance is created at the same time as a Poll and reused on each call to Poll::poll.

See Poll for more documentation on polling.

Examples

use mio::{Events, Poll};
use std::time::Duration;

let mut events = Events::with_capacity(1024);
let mut poll = Poll::new()?;

// Register `event::Source`s with `poll`.

poll.poll(&mut events, Some(Duration::from_millis(100)))?;

for event in events.iter() {
    println!("Got an event for {:?}", event.token());
}

Implementations§

source§

impl Events

source

pub fn with_capacity(capacity: usize) -> Events

Return a new Events capable of holding up to capacity events.

Examples
use mio::Events;

let events = Events::with_capacity(1024);
assert_eq!(1024, events.capacity());
source

pub fn capacity(&self) -> usize

Returns the number of Event values that self can hold.

use mio::Events;

let events = Events::with_capacity(1024);
assert_eq!(1024, events.capacity());
source

pub fn is_empty(&self) -> bool

Returns true if self contains no Event values.

Examples
use mio::Events;

let events = Events::with_capacity(1024);
assert!(events.is_empty());
source

pub fn iter(&self) -> Iter<'_>

Returns an iterator over the Event values.

Examples
use mio::{Events, Poll};
use std::time::Duration;

let mut events = Events::with_capacity(1024);
let mut poll = Poll::new()?;

// Register handles with `poll`.

poll.poll(&mut events, Some(Duration::from_millis(100)))?;

for event in events.iter() {
    println!("Got an event for {:?}", event.token());
}
source

pub fn clear(&mut self)

Clearing all Event values from container explicitly.

Notes

Events are cleared before every poll, so it is not required to call this manually.

Examples
use mio::{Events, Poll};
use std::time::Duration;

let mut events = Events::with_capacity(1024);
let mut poll = Poll::new()?;

// Register handles with `poll`.

poll.poll(&mut events, Some(Duration::from_millis(100)))?;

// Clear all events.
events.clear();
assert!(events.is_empty());

Trait Implementations§

source§

impl Debug for Events

source§

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

Formats the value using the given formatter. Read more
source§

impl<'a> IntoIterator for &'a Events

§

type Item = &'a Event

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.