pub trait MessageReactor:
Unpin
+ Send
+ 'static {
type Inbound;
// Required method
fn on_inbound_messages(
&mut self,
messages: impl IntoIterator<Item = Self::Inbound>,
) -> ReactorStatus;
}Expand description
A message reactor is a stateful object that processes inbound messages. You receive &mut self, and you receive your messages by value.
A message reactor may be a server which spawns a task per message, or a client which matches response ids to a HashMap of concurrent requests with oneshot completions.
Your message reactor and your tcp connection share their fate - when one drops or disconnects, the other does too.
Required Associated Types§
Required Methods§
Sourcefn on_inbound_messages(
&mut self,
messages: impl IntoIterator<Item = Self::Inbound>,
) -> ReactorStatus
fn on_inbound_messages( &mut self, messages: impl IntoIterator<Item = Self::Inbound>, ) -> ReactorStatus
Called from the connection’s driver task when messages are received.
You must take all of the messages quickly: Blocking here will block the connection. If you can’t accept new messages and you can’t queue, you should consider returning Disconnect.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.