pub trait InboundPolicy {
// Required method
fn review(
&mut self,
message: &Message,
) -> Option<(ReceptionStatusValues, String)>;
}Expand description
A hook consulted before an inbound message is acknowledged.
The engine chooses every reception status itself, because an acknowledgement that an
application can forget is one that will be forgotten. This is the exception: the two
statuses that are about the receiver rather than the message —
TEMPORARY_ERROR (“Receiver encountered an error”, so try again) and
PERMANENT_ERROR (“an error which it cannot recover from”, so disconnect) — are
things only the application knows about.
It is called synchronously, inside handle_text, and must not block.
use s2_kit::prelude::*;
use s2_kit::session::InboundPolicy;
struct RefuseWhenStorageIsDown {
storage_available: bool,
}
impl InboundPolicy for RefuseWhenStorageIsDown {
fn review(&mut self, message: &Message) -> Option<(ReceptionStatusValues, String)> {
if !self.storage_available && message.is_instruction() {
return Some((
ReceptionStatusValues::TemporaryError,
"the device is not reachable right now".into(),
));
}
None
}
}Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".