/// 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. /// /// [`Poll::poll`]: ../struct.Poll.html#method.poll /// [`Poll`]: ../struct.Poll.html /// /// # Examples /// #[cfg_attr(feature = "os-poll", doc = "```")] #[cfg_attr(not(feature = "os-poll"), doc = "```ignore")] /// # 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(()) /// # } /// ``` pubstruct Events {
inner: sys::Events,
}
/// [`Events`] iterator. /// /// This struct is created by the [`iter`] method on [`Events`]. /// /// [`Events`]: struct.Events.html /// [`iter`]: struct.Events.html#method.iter /// /// # Examples /// #[cfg_attr(feature = "os-poll", doc = "```")] #[cfg_attr(not(feature = "os-poll"), doc = "```ignore")] /// # 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(()) /// # } /// ``` #[derive(Debug, Clone)] pubstruct Iter<'a> {
inner: &'a Events,
pos: usize,
}
impl 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()); /// ``` pubfn with_capacity(capacity: usize) -> Events {
Events {
inner: sys::Events::with_capacity(capacity),
}
}
/// Returns the number of `Event` values that `self` can hold. /// /// ``` /// use mio::Events; /// /// let events = Events::with_capacity(1024); /// assert_eq!(1024, events.capacity()); /// ``` pubfn capacity(&self) -> usize { self.inner.capacity()
}
/// Returns `true` if `self` contains no `Event` values. /// /// # Examples /// /// ``` /// use mio::Events; /// /// let events = Events::with_capacity(1024); /// assert!(events.is_empty()); /// ``` pubfn is_empty(&self) -> bool { self.inner.is_empty()
}
/// Returns an iterator over the `Event` values. /// /// # Examples /// #[cfg_attr(feature = "os-poll", doc = "```")] #[cfg_attr(not(feature = "os-poll"), doc = "```ignore")] /// # 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(()) /// # } /// ``` pubfn iter(&self) -> Iter<'_> {
Iter {
inner: self,
pos: 0,
}
}
/// Clearing all `Event` values from container explicitly. /// /// # Notes /// /// Events are cleared before every `poll`, so it is not required to call /// this manually. /// /// # Examples /// #[cfg_attr(feature = "os-poll", doc = "```")] #[cfg_attr(not(feature = "os-poll"), doc = "```ignore")] /// # 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(()) /// # } /// ``` pubfn clear(&mutself) { self.inner.clear();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.