Trait SessionState
pub trait SessionState {
Show 14 methods
// Required methods
fn store_outgoing_qos1(
&mut self,
packet_id: PacketId,
topic: &Topic,
payload: &[u8],
retain: bool,
properties: &PublishProperties,
);
fn remove_outgoing_qos1(&mut self, packet_id: PacketId);
fn store_outgoing_qos2(
&mut self,
packet_id: PacketId,
phase: Qos2Phase,
topic: &Topic,
payload: &[u8],
retain: bool,
properties: &PublishProperties,
);
fn advance_outgoing_qos2(&mut self, packet_id: PacketId);
fn remove_outgoing_qos2(&mut self, packet_id: PacketId);
fn store_incoming_qos2(&mut self, packet_id: PacketId);
fn remove_incoming_qos2(&mut self, packet_id: PacketId);
fn has_outgoing_qos1(&self, packet_id: PacketId) -> bool;
fn has_outgoing_qos2(&self, packet_id: PacketId) -> bool;
fn has_incoming_qos2(&self, packet_id: PacketId) -> bool;
fn try_for_each_outgoing_qos1<B>(
&self,
f: Qos1Callback<'_, B>,
) -> ControlFlow<B>;
fn try_for_each_outgoing_qos2<B>(
&self,
f: &mut dyn FnMut(OutgoingQos2<'_>) -> ControlFlow<B>,
) -> ControlFlow<B>;
fn try_for_each_incoming_qos2<B>(
&self,
f: &mut dyn FnMut(PacketId) -> ControlFlow<B>,
) -> ControlFlow<B>;
fn clear(&mut self);
}Expand description
Persistent session state that must survive across network connections.
§Contract
Implementors must persist state durably when
Session Expiry Interval > 0 (§3.1.2.11.2). When the interval is 0 (or
absent), state only needs to live for the duration of the network
connection.
§No-alloc note
This trait uses an iterator-based try_for_each_* pattern instead of
returning collections, keeping the crate no_alloc-compatible.
§Callback type alias
Qos1Callback is provided to keep the QoS 1 visitor signature
readable.
Required Methods§
fn store_outgoing_qos1(
&mut self,
packet_id: PacketId,
topic: &Topic,
payload: &[u8],
retain: bool,
properties: &PublishProperties,
)
fn store_outgoing_qos1( &mut self, packet_id: PacketId, topic: &Topic, payload: &[u8], retain: bool, properties: &PublishProperties, )
Store a QoS 1 outbound publish (PUBLISH sent, awaiting PUBACK).
packet_id is the identifier assigned to the PUBLISH.
topic and payload are the message content that must be stored
so the message can be retransmitted with DUP=1 on reconnect.
fn remove_outgoing_qos1(&mut self, packet_id: PacketId)
fn remove_outgoing_qos1(&mut self, packet_id: PacketId)
Remove a QoS 1 outbound publish after PUBACK is received.
fn store_outgoing_qos2(
&mut self,
packet_id: PacketId,
phase: Qos2Phase,
topic: &Topic,
payload: &[u8],
retain: bool,
properties: &PublishProperties,
)
fn store_outgoing_qos2( &mut self, packet_id: PacketId, phase: Qos2Phase, topic: &Topic, payload: &[u8], retain: bool, properties: &PublishProperties, )
Store a QoS 2 outbound publish.
When phase is Qos2Phase::AwaitingPubrec, topic and payload
contain the message content. When phase is
Qos2Phase::AwaitingPubcomp, they may be empty (the implementation
should discard the message payload per §4.3.3).
fn advance_outgoing_qos2(&mut self, packet_id: PacketId)
fn advance_outgoing_qos2(&mut self, packet_id: PacketId)
Advance a QoS 2 outbound publish to the PUBREL-sent phase.
Called when PUBREC is received with rc < 0x80. Implementations should update the phase and may discard the message payload.
fn remove_outgoing_qos2(&mut self, packet_id: PacketId)
fn remove_outgoing_qos2(&mut self, packet_id: PacketId)
Remove a QoS 2 outbound publish after PUBCOMP is received (or PUBREC
with rc ≥ 0x80).
fn store_incoming_qos2(&mut self, packet_id: PacketId)
fn store_incoming_qos2(&mut self, packet_id: PacketId)
Store a QoS 2 inbound packet identifier (PUBREC sent, awaiting
PUBREL from the server).
fn remove_incoming_qos2(&mut self, packet_id: PacketId)
fn remove_incoming_qos2(&mut self, packet_id: PacketId)
Remove a QoS 2 inbound packet identifier after PUBREL is received
and PUBCOMP has been sent.
fn has_outgoing_qos1(&self, packet_id: PacketId) -> bool
fn has_outgoing_qos1(&self, packet_id: PacketId) -> bool
Check whether a QoS 1 outbound publish is stored for this packet ID.
fn has_outgoing_qos2(&self, packet_id: PacketId) -> bool
fn has_outgoing_qos2(&self, packet_id: PacketId) -> bool
Check whether a QoS 2 outbound publish is stored for this packet ID.
fn has_incoming_qos2(&self, packet_id: PacketId) -> bool
fn has_incoming_qos2(&self, packet_id: PacketId) -> bool
Check whether a QoS 2 inbound packet identifier is stored (i.e.,
PUBREC was already sent for this packet ID).
fn try_for_each_outgoing_qos1<B>(
&self,
f: Qos1Callback<'_, B>,
) -> ControlFlow<B>
fn try_for_each_outgoing_qos1<B>( &self, f: Qos1Callback<'_, B>, ) -> ControlFlow<B>
Iterate over all stored outgoing QoS 1 messages for retransmission
on reconnect.
The callback receives (packet_id, topic, payload) for each stored
message. Return ControlFlow::Break to stop early.
fn try_for_each_outgoing_qos2<B>(
&self,
f: &mut dyn FnMut(OutgoingQos2<'_>) -> ControlFlow<B>,
) -> ControlFlow<B>
fn try_for_each_outgoing_qos2<B>( &self, f: &mut dyn FnMut(OutgoingQos2<'_>) -> ControlFlow<B>, ) -> ControlFlow<B>
Iterate over all stored outgoing QoS 2 messages for retransmission
on reconnect.
For messages in Qos2Phase::AwaitingPubcomp, topic and payload
may be empty. Return ControlFlow::Break to stop early.
fn try_for_each_incoming_qos2<B>(
&self,
f: &mut dyn FnMut(PacketId) -> ControlFlow<B>,
) -> ControlFlow<B>
fn try_for_each_incoming_qos2<B>( &self, f: &mut dyn FnMut(PacketId) -> ControlFlow<B>, ) -> ControlFlow<B>
Iterate over all stored incoming QoS 2 packet identifiers for
re-acknowledging on reconnect.
Return ControlFlow::Break to stop early.
fn clear(&mut self)
fn clear(&mut self)
Clear all session state. Called when connecting with
Clean Start = 1.
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.
Implementors§
impl SessionState for InMemorySession
alloc only.impl SessionState for JournaledSession
alloc only.