Trait racetime::handler::RaceHandler

source ·
pub trait RaceHandler<S: Send + Sync + ?Sized + 'static>: Send + Sized + 'static {
Show 17 methods // Required method fn new<'life0, 'async_trait>( ctx: &'life0 RaceContext<S> ) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided methods fn should_handle<'life0, 'async_trait>( race_data: &'life0 RaceData, _state: Arc<S> ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>> where 'life0: 'async_trait { ... } fn command<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _cmd_name: String, _args: Vec<String>, _is_moderator: bool, _is_monitor: bool, _msg: &'life2 ChatMessage ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn should_stop<'life0, 'life1, 'async_trait>( &'life0 mut self, ctx: &'life1 RaceContext<S> ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn end<'life0, 'async_trait>( self, _ctx: &'life0 RaceContext<S> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn chat_history<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _msgs: Vec<ChatMessage> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn chat_message<'life0, 'life1, 'async_trait>( &'life0 mut self, ctx: &'life1 RaceContext<S>, message: ChatMessage ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn chat_pin<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _message: ChatMessage ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn chat_unpin<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _message: ChatMessage ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn chat_delete<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _event: ChatDelete ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn chat_purge<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _event: ChatPurge ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn error<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, errors: Vec<String> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn pong<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn race_data<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _old_race_data: RaceData ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn race_renders<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn race_split<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn task<'async_trait>( _state: Arc<S>, _race_data: Arc<RwLock<RaceData>>, _join_handle: JoinHandle<()> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> { ... }
}
Expand description

This trait should be implemented using the async_trait attribute.

Required Methods§

source

fn new<'life0, 'async_trait>( ctx: &'life0 RaceContext<S> ) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called when a new race room is found and should_handle has returned true.

Equivalent to:

async fn new(ctx: &RaceContext<S>) -> Result<Self, Error>;

The RaceHandler this returns will receive events for that race.

Provided Methods§

source

fn should_handle<'life0, 'async_trait>( race_data: &'life0 RaceData, _state: Arc<S> ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,

Called when a new race room is found. If this returns false, that race is ignored entirely.

Equivalent to:

async fn should_handle(race_data: &RaceData, _state: Arc<S>) -> Result<bool, Error>;

The default implementation returns true for any race whose status value is neither finished nor cancelled.

source

fn command<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _cmd_name: String, _args: Vec<String>, _is_moderator: bool, _is_monitor: bool, _msg: &'life2 ChatMessage ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called for each chat message that starts with ! and was not sent by the system or a bot.

Equivalent to:

async fn command(&mut self: _ctx: &RaceContext<S>, _cmd_name: String, _args: Vec<String>, _is_moderator: bool, _is_monitor: bool, _msg: &ChatMessage) -> Result<(), Error>;
source

fn should_stop<'life0, 'life1, 'async_trait>( &'life0 mut self, ctx: &'life1 RaceContext<S> ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Determine if the handler should be terminated. This is checked after every receieved message.

Equivalent to:

async fn should_stop(&mut self, ctx: &RaceContext<S>) -> Result<bool, Error>;

The default implementation checks should_handle.

source

fn end<'life0, 'async_trait>( self, _ctx: &'life0 RaceContext<S> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Bot actions to perform just before disconnecting from a race room.

Equivalent to:

async fn end(self, _ctx: &RaceContext<S>) -> Result<(), Error>;

The default implementation does nothing.

source

fn chat_history<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _msgs: Vec<ChatMessage> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a chat.history message is received.

Equivalent to:

async fn chat_history(&mut self, _ctx: &RaceContext<S>: _msgs: Vec<ChatMessage>) -> Result<(), Error>;

The default implementation does nothing.

source

fn chat_message<'life0, 'life1, 'async_trait>( &'life0 mut self, ctx: &'life1 RaceContext<S>, message: ChatMessage ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a chat.message message is received.

Equivalent to:

async fn chat_message(&mut self, ctx: &RaceContext<S>, message: ChatMessage) -> Result<(), Error>;

The default implementation calls command if appropriate.

source

fn chat_pin<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _message: ChatMessage ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a chat.pin message is received.

Equivalent to:

async fn chat_pin(&mut self, _ctx: &RaceContext<S>, _message: ChatMessage) -> Result<(), Error>;

The default implementation does nothing.

source

fn chat_unpin<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _message: ChatMessage ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a chat.unpin message is received.

Equivalent to:

async fn chat_unpin(&mut self, _ctx: &RaceContext<S>, _message: ChatMessage) -> Result<(), Error>;

The default implementation does nothing.

source

fn chat_delete<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _event: ChatDelete ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a chat.delete message is received.

Equivalent to:

async fn chat_delete(&mut self, _ctx: &RaceContext<S>, _event: ChatDelete) -> Result<(), Error>;

The default implementation does nothing.

source

fn chat_purge<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _event: ChatPurge ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a chat.purge message is received.

Equivalent to:

async fn chat_purge(&mut self, _ctx: &RaceContext<S>, _event: ChatPurge) -> Result<(), Error>;

The default implementation does nothing.

source

fn error<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, errors: Vec<String> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when an error message is received.

Equivalent to:

async fn error(&mut self, _ctx: &RaceContext<S>, errors: Vec<String>) -> Result<(), Error>;

The default implementation returns the errors as Error::Server.

source

fn pong<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a pong message is received.

Equivalent to:

async fn pong(&mut self, _ctx: &RaceContext<S>) -> Result<(), Error>;

The default implementation does nothing.

source

fn race_data<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S>, _old_race_data: RaceData ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a race.data message is received.

Equivalent to:

async fn race_data(&mut self, _ctx: &RaceContext<S>, _old_race_data: RaceData) -> Result<(), Error>;

The new race data can be found in the RaceContext parameter. The RaceData parameter contains the previous data.

The default implementation does nothing.

source

fn race_renders<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a race.renders message is received.

Equivalent to:

async fn race_renders(&mut self, _ctx: &RaceContext<S>) -> Result<(), Error>;

The default implementation does nothing.

source

fn race_split<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 RaceContext<S> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a race.split message is received.

Equivalent to:

async fn race_split(&mut self, _ctx: &RaceContext<S>) -> Result<(), Error>;

The default implementation does nothing.

source

fn task<'async_trait>( _state: Arc<S>, _race_data: Arc<RwLock<RaceData>>, _join_handle: JoinHandle<()> ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>

Called when a room handler task is created.

Equivalent to:

async fn task(_state: Arc<S>, _race_data: Arc<RwLock<RaceData>>, _join_handle: tokio::task::JoinHandle<()>) -> Result<(), Error>;

The default implementation does nothing.

Object Safety§

This trait is not object safe.

Implementors§