pub trait Evented {
// Required methods
fn register(
&mut self,
os_queue: &mut OsQueue,
id: Id,
interests: Interests,
opt: RegisterOption,
) -> Result<()>;
fn reregister(
&mut self,
os_queue: &mut OsQueue,
id: Id,
interests: Interests,
opt: RegisterOption,
) -> Result<()>;
fn deregister(&mut self, os_queue: &mut OsQueue) -> Result<()>;
}Expand description
A handle that may be registered with OsQueue.
Handles that implement Evented can be registered with OsQueue. The
methods on the trait should not be called directly, instead the
equivalent methods should be called on OsQueue.
See OsQueue documentation for more details.
§Implementing Evented
Implementations of Evented are always backed by system handles, which
are backed by sockets or other system handles. The Evented handles will be
monitored by the Operating System selector. In this case, an implementation
of Evented delegates to a lower level handle. Examples of this are
TcpStreams, or the unix only EventedFd.
§Dropping Evented types
All Evented types, unless otherwise specified, need to be deregistered
before being dropped for them to not leak resources. This goes against the
normal drop behaviour of types in Rust which cleanup after themselves, e.g.
a File will close itself. However since deregistering needs mutable access
to OsQueue this cannot be done while being dropped.
§Examples
Implementing Evented on a struct containing a system handle, such as a
TcpStream.
use std::io;
use gaea::event;
use gaea::net::TcpStream;
use gaea::os::{Evented, Interests, RegisterOption, OsQueue};
pub struct MyEvented {
/// Our system handle that implements `Evented`.
socket: TcpStream,
}
impl Evented for MyEvented {
fn register(&mut self, os_queue: &mut OsQueue, id: event::Id, interests: Interests, opt: RegisterOption) -> io::Result<()> {
// Delegate the `register` call to `socket`.
self.socket.register(os_queue, id, interests, opt)
}
fn reregister(&mut self, os_queue: &mut OsQueue, id: event::Id, interests: Interests, opt: RegisterOption) -> io::Result<()> {
// Delegate the `reregister` call to `socket`.
self.socket.reregister(os_queue, id, interests, opt)
}
fn deregister(&mut self, os_queue: &mut OsQueue) -> io::Result<()> {
// Delegate the `deregister` call to `socket`.
self.socket.deregister(os_queue)
}
}Required Methods§
Sourcefn register(
&mut self,
os_queue: &mut OsQueue,
id: Id,
interests: Interests,
opt: RegisterOption,
) -> Result<()>
fn register( &mut self, os_queue: &mut OsQueue, id: Id, interests: Interests, opt: RegisterOption, ) -> Result<()>
Register self with the given OsQueue instance.
This function should not be called directly, use OsQueue.register
instead.
Sourcefn reregister(
&mut self,
os_queue: &mut OsQueue,
id: Id,
interests: Interests,
opt: RegisterOption,
) -> Result<()>
fn reregister( &mut self, os_queue: &mut OsQueue, id: Id, interests: Interests, opt: RegisterOption, ) -> Result<()>
Reregister self with the given OsQueue instance.
This function should not be called directly, use OsQueue.reregister
instead.
Sourcefn deregister(&mut self, os_queue: &mut OsQueue) -> Result<()>
fn deregister(&mut self, os_queue: &mut OsQueue) -> Result<()>
Deregister self from the given OsQueue instance
This function should not be called directly, use OsQueue.deregister
instead.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".