Skip to main content

EventLoopTrait

Trait EventLoopTrait 

Source
pub trait EventLoopTrait<T: AsRawFd> {
    // Required methods
    fn new(event_capacity: usize) -> Result<Self, CommonError>
       where Self: Sized;
    fn generate_token(&self) -> Token;
    fn register_event_source(
        &self,
        event_source: T,
        callback: CallBack<T>,
    ) -> Result<Token, CommonError>;
    fn unregister_event_source(&self, token: Token) -> Result<(), CommonError>;
    fn unregister_timed_event_source(
        &self,
        token: Token,
    ) -> Result<(), CommonError>;
    fn run(&mut self) -> Result<(), CommonError>;
    fn add_duration(&self, time_spec: &Itimerspec) -> Result<Token, CommonError>;
    fn add_cleanup(
        &mut self,
        time_spec: &Itimerspec,
    ) -> Result<Token, CommonError>;
    fn register_timer(
        &self,
        time_spec: &Itimerspec,
        token: &Token,
        callback: CallBack<T>,
    ) -> Result<Token, CommonError>;
}
Expand description

EventLoopTrait defines the behavior for an event loop.

This trait is implemented by types that can be used to manage and control event-driven systems, such as network services.

Required Methods§

Source

fn new(event_capacity: usize) -> Result<Self, CommonError>
where Self: Sized,

Creates a new event loop instance with the given capacity.

§Errors

Returns CommonError if the creation fails.

Source

fn generate_token(&self) -> Token

Generates a new unique token.

Tokens are used to identify registered event sources.

Source

fn register_event_source( &self, event_source: T, callback: CallBack<T>, ) -> Result<Token, CommonError>

Registers an event source to the event loop.

The event_source is the entity that can produce events. The callback is a function that will be called when an event is received for the registered event_source.

§Errors

Returns CommonError if the registration fails.

Source

fn unregister_event_source(&self, token: Token) -> Result<(), CommonError>

Unregisters the specified event source from the event loop.

The token identifies the event source to be unregistered.

§Errors

Returns CommonError if the unregistration fails.

Source

fn unregister_timed_event_source(&self, token: Token) -> Result<(), CommonError>

Unregisters a timed event source from the event loop.

The token identifies the timed event source to be unregistered.

§Errors

Returns CommonError if the unregistration fails.

Source

fn run(&mut self) -> Result<(), CommonError>

Runs the event loop.

The event loop will keep running until an error occurs or it is manually stopped.

§Errors

Returns CommonError if running the event loop fails.

Source

fn add_duration(&self, time_spec: &Itimerspec) -> Result<Token, CommonError>

Adds a timed event to the event loop.

The time_spec specifies when the event should be triggered.

§Errors

Returns CommonError if adding the timed event fails.

Source

fn add_cleanup(&mut self, time_spec: &Itimerspec) -> Result<Token, CommonError>

Adds a timed event that clears all registered events to the event loop.

The time_spec specifies when the event should be triggered.

§Errors

Returns CommonError if adding the timed event fails.

Source

fn register_timer( &self, time_spec: &Itimerspec, token: &Token, callback: CallBack<T>, ) -> Result<Token, CommonError>

Adds a timer to the event loop.

The time_spec specifies when the timer should be triggered. The token is the identifier for the timer. The callback is a function that will be called when the timer is triggered.

§Errors

Returns CommonError if adding the timer fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: AsRawFd + Send + 'static> EventLoopTrait<T> for LinuxEventLoop<T>