Struct Events

struct Events { ... }

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 std::error::Error;
# fn main() -> Result<(), Box<dyn Error>> {
use mio::{Events, Poll};
use std::time::Duration;

let mut events = Events::with_capacity(1024);
let mut poll = Poll::new()?;
#
# assert!(events.is_empty());

// 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());
}
#     Ok(())
# }

Implementations

impl Events

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());
fn capacity(self: &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());
fn is_empty(self: &Self) -> bool

Returns true if self contains no Event values.

Examples

use mio::Events;

let events = Events::with_capacity(1024);
assert!(events.is_empty());
fn iter(self: &Self) -> Iter<'_>

Returns an iterator over the Event values.

Examples

# use std::error::Error;
# fn main() -> Result<(), Box<dyn Error>> {
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());
}
#     Ok(())
# }
fn clear(self: &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 std::error::Error;
# fn main() -> Result<(), Box<dyn Error>> {
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());
#     Ok(())
# }

impl Debug for Events

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

impl Freeze for Events

impl RefUnwindSafe for Events

impl Send for Events

impl Sync for Events

impl Unpin for Events

impl UnsafeUnpin for Events

impl UnwindSafe for Events

impl<T> Any for Events

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Events

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Events

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for Events

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for Events

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Events

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Events

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>