Struct InMemorySession
pub struct InMemorySession {
outbox: BTreeMap<PacketId, StoredOutboxEntry>,
pubrel_pending: BTreeMap<PacketId, bool>,
incoming_qos2: BTreeSet<PacketId>,
filters: BTreeMap<Arc<TopicFilter>, FilterEntryData>,
pending_index: BTreeMap<(PacketId, u16), Arc<TopicFilter>>,
}alloc only.Expand description
In-memory implementation of SessionState.
All state lives on the heap and is lost when the struct is dropped.
Suitable for clients that always connect with Clean Start = 1 or
that do not need durable session persistence.
Fields§
§outbox: BTreeMap<PacketId, StoredOutboxEntry>§pubrel_pending: BTreeMap<PacketId, bool>Maps each PUBREL-pending packet id to its transient in-flight marker
(see StoredOutboxEntry::in_flight).
incoming_qos2: BTreeSet<PacketId>§filters: BTreeMap<Arc<TopicFilter>, FilterEntryData>Every topic filter the application has touched, each a single entry with a single lifecycle state. Replaces the old confirmed-subscription store plus the separate pending SUBSCRIBE/UNSUBSCRIBE maps.
pending_index: BTreeMap<(PacketId, u16), Arc<TopicFilter>>Ordering index for Subscribing/Unsubscribing entries that are not
yet in-flight. Keyed by (packet_id, index) so iteration is already in
the order the filters appear in their SUBSCRIBE/UNSUBSCRIBE packet.
Invariant: contains exactly the entries from filters that are in a
pending (not-in-flight) Subscribing or Unsubscribing state.
Implementations§
§impl InMemorySession
impl InMemorySession
pub const fn new() -> Self
pub const fn new() -> Self
Creates a new, empty in-memory session.
pub fn store_outbox_entry(
&mut self,
packet_id: PacketId,
entry: &OutboxEntry<'_>,
)
pub fn store_outbox_entry( &mut self, packet_id: PacketId, entry: &OutboxEntry<'_>, )
Stores or replaces an outbox entry.
pub fn remove_outbox_entry(&mut self, packet_id: PacketId) -> Applied
pub fn remove_outbox_entry(&mut self, packet_id: PacketId) -> Applied
Removes an outbox entry.
pub fn mark_outbox_entry_sent(&mut self, packet_id: PacketId)
pub fn mark_outbox_entry_sent(&mut self, packet_id: PacketId)
Marks an outbox entry as having been written to the wire at least once.
pub fn store_pubrel_pending(&mut self, packet_id: PacketId)
pub fn store_pubrel_pending(&mut self, packet_id: PacketId)
Stores a QoS 2 entry in the pubrel-pending set.
pub fn remove_pubrel_pending(&mut self, packet_id: PacketId) -> Applied
pub fn remove_pubrel_pending(&mut self, packet_id: PacketId) -> Applied
Removes a QoS 2 entry from the pubrel-pending set.
pub fn store_incoming_qos2(&mut self, packet_id: PacketId)
pub fn store_incoming_qos2(&mut self, packet_id: PacketId)
Stores an incoming QoS 2 publish in the awaiting-PUBREL set.
pub fn remove_incoming_qos2(&mut self, packet_id: PacketId) -> Applied
pub fn remove_incoming_qos2(&mut self, packet_id: PacketId) -> Applied
Removes an incoming QoS 2 publish.
pub fn set_filter_entry(&mut self, entry: FilterEntry<'_>)
pub fn set_filter_entry(&mut self, entry: FilterEntry<'_>)
Stores or replaces a filter entry verbatim, keeping the pending index in sync with the entry’s state.
pub fn remove_filter(&mut self, filter: &TopicFilter) -> Applied
pub fn remove_filter(&mut self, filter: &TopicFilter) -> Applied
Removes a filter entry.
pub fn clear_in_flight(&mut self)
pub fn clear_in_flight(&mut self)
Clears all in-flight state. Confirmed subscriptions are preserved.
pub fn resolve_pending(
&mut self,
packet_id: PacketId,
decide: &mut dyn FnMut(FilterEntry<'_>) -> Resolution,
)
pub fn resolve_pending( &mut self, packet_id: PacketId, decide: &mut dyn FnMut(FilterEntry<'_>) -> Resolution, )
Mechanical resolution of the pending entries under packet_id; the
closure owns the SUBACK/UNSUBACK semantics (see
SessionState::resolve_pending).
Trait Implementations§
§impl Default for InMemorySession
impl Default for InMemorySession
§impl SessionState for InMemorySession
impl SessionState for InMemorySession
§fn apply(&mut self, op: SessionOp<'_>) -> Applied
fn apply(&mut self, op: SessionOp<'_>) -> Applied
§fn reset_outbox_sent_flags(&mut self)
fn reset_outbox_sent_flags(&mut self)
§fn for_each_outbox_entry(&self, f: &mut dyn FnMut(PacketId, OutboxEntry<'_>))
fn for_each_outbox_entry(&self, f: &mut dyn FnMut(PacketId, OutboxEntry<'_>))
§fn drain_outbox(
&mut self,
visit: &mut dyn FnMut(PacketId, OutboxEntry<'_>) -> DrainAction,
)
fn drain_outbox( &mut self, visit: &mut dyn FnMut(PacketId, OutboxEntry<'_>) -> DrainAction, )
DrainAction the visitor
returns: Sent marks it in-flight and was_sent;
Discard removes it;
Stop halts the walk. This is the single
outbound send path, so the visitor is the only place a publish
reaches the wire.§fn reset_in_flight(&mut self)
fn reset_in_flight(&mut self)
§fn has_pubrel_pending(&self, packet_id: PacketId) -> bool
fn has_pubrel_pending(&self, packet_id: PacketId) -> bool
true if a PUBREL is pending for packet_id (the QoS 2
publish is in the awaiting-PUBCOMP phase). Read more§fn for_each_pubrel_pending(&self, f: &mut dyn FnMut(PacketId))
fn for_each_pubrel_pending(&self, f: &mut dyn FnMut(PacketId))
§fn drain_pubrel(&mut self, visit: &mut dyn FnMut(PacketId) -> DrainAction)
fn drain_pubrel(&mut self, visit: &mut dyn FnMut(PacketId) -> DrainAction)
DrainAction. Mirrors
drain_outbox for the QoS 2 PUBREL resend.§fn has_incoming_qos2(&self, packet_id: PacketId) -> bool
fn has_incoming_qos2(&self, packet_id: PacketId) -> bool
QoS 2 packet identifier is stored (i.e.,
PUBREC was already sent for this packet ID).§fn clear_incoming_qos2(&mut self)
fn clear_incoming_qos2(&mut self)
QoS 2 packet identifiers. Read more§fn for_each_incoming_qos2(&self, f: &mut dyn FnMut(PacketId))
fn for_each_incoming_qos2(&self, f: &mut dyn FnMut(PacketId))
QoS 2 packet identifier.§fn get_filter_entry(&self, filter: &TopicFilter) -> Option<FilterEntry<'_>>
fn get_filter_entry(&self, filter: &TopicFilter) -> Option<FilterEntry<'_>>
None if it
has not been touched. Used by the client to determine the filter’s
current state before recording an UNSUBSCRIBE transition.§fn resolve_pending(
&mut self,
packet_id: PacketId,
decide: &mut dyn FnMut(FilterEntry<'_>) -> Resolution,
)
fn resolve_pending( &mut self, packet_id: PacketId, decide: &mut dyn FnMut(FilterEntry<'_>) -> Resolution, )
Subscribing or
Unsubscribing) under packet_id and applies the returned
Resolution, dropping the entry’s pending-order slot for every
decision other than Resolution::Keep.§fn for_each_active_subscription(&self, f: &mut dyn FnMut(Subscription<'_>))
fn for_each_active_subscription(&self, f: &mut dyn FnMut(Subscription<'_>))
Subscribed filter (the
application’s active subscriptions). In-flight Subscribing/
Unsubscribing entries are skipped.§fn for_each_filter_entry(&self, f: &mut dyn FnMut(FilterEntry<'_>))
fn for_each_filter_entry(&self, f: &mut dyn FnMut(FilterEntry<'_>))
§fn first_pending_group(&self) -> Option<PendingMeta>
fn first_pending_group(&self) -> Option<PendingMeta>
None
when none remain. This is a read-only peek; the caller iterates the
group’s filters
(pending_subscribe_filters /
pending_unsubscribe_filters),
enqueues the packet, then commits the group with
mark_subscription_in_flight. Read more§fn pending_subscribe_filters(
&self,
packet_id: PacketId,
) -> impl Iterator<Item = (&TopicFilter, SubscriptionOptions)>
fn pending_subscribe_filters( &self, packet_id: PacketId, ) -> impl Iterator<Item = (&TopicFilter, SubscriptionOptions)>
packet_id, in
packet order (their position in the SUBACK), each with its subscription
options. Empty unless packet_id is a pending SUBSCRIBE.§fn pending_unsubscribe_filters(
&self,
packet_id: PacketId,
) -> impl Iterator<Item = &TopicFilter>
fn pending_unsubscribe_filters( &self, packet_id: PacketId, ) -> impl Iterator<Item = &TopicFilter>
packet_id, in
packet order. Empty unless packet_id is a pending UNSUBSCRIBE.§fn mark_subscription_in_flight(&mut self, packet_id: PacketId)
fn mark_subscription_in_flight(&mut self, packet_id: PacketId)
packet_id in flight and drops the group from
the pending set, so the next
first_pending_group skips it until
reset_in_flight re-arms it. Called once
the group’s packet has been enqueued.§fn is_packet_id_in_use(&self, packet_id: PacketId) -> bool
fn is_packet_id_in_use(&self, packet_id: PacketId) -> bool
true if packet_id is currently occupied by any tracked
operation: an outbox entry, a PUBREL-pending entry, or an in-flight
SUBSCRIBE/UNSUBSCRIBE. Read more