Skip to main content

InMemory

Struct InMemory 

pub struct InMemory {
    outbox: SortedMap<PacketId, StoredOutboxEntry>,
    pubrel_pending: SortedMap<PacketId, bool>,
    incoming_qos2: SortedMap<PacketId, ()>,
    filters: Filters<FilterEntryData>,
    pending_index: SortedMap<(Slot, FilterId), ()>,
}
Available on crate feature alloc only.
Expand description

In-memory implementation of State.

The session stores its state on the heap. The state is lost when the struct is dropped. Storing reports a failed allocation as TryReserveError. Suitable for clients that always connect with Clean Start = 1 or that do not need durable session persistence.

Fields§

§outbox: SortedMap<PacketId, StoredOutboxEntry>§pubrel_pending: SortedMap<PacketId, bool>

Maps each PUBREL-pending packet id to its transient in-flight marker (see StoredOutboxEntry::in_flight).

§incoming_qos2: SortedMap<PacketId, ()>§filters: Filters<FilterEntryData>

Every topic filter the application has touched, each one entry with one lifecycle state.

§pending_index: SortedMap<(Slot, FilterId), ()>

The entries waiting to be sent: first the Resubscribing ones, then the Subscribing/Unsubscribing ones grouped by the packet id of their request. Iteration within a group is the order of the filters in its SUBSCRIBE/UNSUBSCRIBE packet. Invariant: contains exactly the entries from filters with a Slot, and has room for every filter.

Implementations§

§

impl InMemory

pub const fn new() -> Self

Creates a new, empty in-memory session.

fn store_outbox_entry( &mut self, packet_id: PacketId, entry: &OutboxEntry<'_>, ) -> Result<(), TryReserveError>

fn remove_outbox_entry(&mut self, packet_id: PacketId) -> Applied

fn mark_outbox_entry_sent(&mut self, packet_id: PacketId)

fn remove_pubrel_pending(&mut self, packet_id: PacketId) -> Applied

fn remove_incoming_qos2(&mut self, packet_id: PacketId) -> Applied

fn store_filter( &mut self, entry: FilterEntry<'_>, ) -> Result<(), TryReserveError>

Stores or replaces a filter entry verbatim.

The pending index keeps room for every stored filter, so a later set_filter_state never allocates.

fn set_filter_state( &mut self, filter: &TopicFilter, state: FilterState, ) -> Applied

Changes the state of a stored filter entry.

fn reindex(&mut self, id: FilterId, old: Option<FilterState>, new: FilterState)

Moves the pending-index slot of filter id from old to new.

fn remove_filter(&mut self, filter: &TopicFilter) -> Applied

fn clear_in_flight(&mut self)

Clears all in-flight state. Confirmed subscriptions are preserved.

fn rebuild_index(&mut self)

Rebuilds the pending index from the filter states. Never allocates, since the index has room for every filter.

Trait Implementations§

§

impl Debug for InMemory

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Default for InMemory

§

fn default() -> Self

Returns the “default value” for a type. Read more
§

impl State for InMemory

§

type Error = TryReserveError

Error returned when the session has no room for new data.
§

fn store(&mut self, op: Store<'_>) -> Result<(), TryReserveError>

Stores new data. Read more
§

fn modify(&mut self, op: Modify<'_>) -> Applied

Changes or removes stored data. Never needs new storage. Read more
§

fn for_each_outbox_entry(&self, f: &mut dyn FnMut(PacketId, OutboxEntry<'_>))

Iterates over every outbox entry. Read more
§

fn drain_outbox( &mut self, visit: &mut dyn FnMut(PacketId, OutboxEntry<'_>) -> DrainAction, )

Visits each outbox entry not already in flight on the current connection, in packet-id order, applying the DrainAction the visitor returns. Sent marks it in-flight and was_sent. Discard removes it. Stop halts the walk. This is the only outbound send path, so the visitor is the only place that writes a publish to the wire.
§

fn reset_in_flight(&mut self)

Clears the in-flight marker on every outbox entry, PUBREL-pending entry, and in-flight SUBSCRIBE/UNSUBSCRIBE request. Read more
§

fn has_outbox_entry(&self, packet_id: PacketId) -> bool

Returns true if the outbox contains a publish under packet_id.
§

fn has_pubrel_pending(&self, packet_id: PacketId) -> bool

Returns 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))

Iterates over every PUBREL-pending packet identifier. Read more
§

fn drain_pubrel(&mut self, visit: &mut dyn FnMut(PacketId) -> DrainAction)

Visits each PUBREL-pending entry not already in flight on the current connection, applying the returned DrainAction. Mirrors drain_outbox for the QoS 2 PUBREL resend.
§

fn has_incoming_qos2(&self, packet_id: PacketId) -> bool

Checks whether an incoming QoS 2 packet identifier is stored (i.e., PUBREC was already sent for this packet ID).
§

fn for_each_incoming_qos2(&self, f: &mut dyn FnMut(PacketId))

Iterates over every stored incoming QoS 2 packet identifier.
§

fn get_filter_entry(&self, filter: &TopicFilter) -> Option<FilterEntry<'_>>

Returns the stored entry for a topic filter, or 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<'_>, usize) -> Resolution, )

Visits every filter entry pending (Subscribing or Unsubscribing) under packet_id, in packet order, and applies the returned Resolution. decide also receives the position of the entry as pending_filters reports it.
§

fn for_each_filter_entry(&self, f: &mut dyn FnMut(FilterEntry<'_>))

Iterates over every filter entry with its full state, for snapshotting (compaction/persistence).
§

fn first_pending_group(&self) -> Option<PendingMeta>

Returns the pending SUBSCRIBE/UNSUBSCRIBE group with the lowest packet id that is not already in flight on the current connection, or None when none remain. This is a read-only peek; the caller iterates the group’s filters with pending_filters, enqueues the packet, then commits the group with mark_subscription_in_flight. Read more
§

fn pending_filters( &self, packet_id: PacketId, ) -> impl Iterator<Item = (FilterEntry<'_>, usize)>

Iterates the filters of the pending request under packet_id, in packet order, each with its position in the packet. Once the request is marked with mark_subscription_in_flight, the position is the one at that time, even if filters have left the request since. It is the position of the filter’s reason code in the SUBACK or UNSUBACK.
§

fn has_resubscribe(&self) -> bool

Returns true if a Resubscribing filter waits to be sent again.
§

fn start_resubscribe(&mut self, packet_id: PacketId) -> Option<FilterEntry<'_>>

Starts the SUBSCRIBE of one Resubscribing filter under the free packet_id. The new state is the one FilterState::resubscribe returns. Returns the changed entry, or None if no filter waits to be resubscribed. Never allocates.
§

fn forget_server_state(&mut self)

Discards what the server forgot when it lost the session (§4.1). Read more
§

fn mark_subscription_in_flight(&mut self, packet_id: PacketId)

Marks every filter under packet_id in flight, so the next first_pending_group skips the group until reset_in_flight re-arms it. Also records the position of each filter in the packet for resolve_pending. Called once the group’s packet has been enqueued.
§

fn is_packet_id_in_use(&self, packet_id: PacketId) -> bool

Returns true if packet_id is currently occupied by any tracked operation. This includes outbox entries, PUBREL-pending entries and in-flight SUBSCRIBE/UNSUBSCRIBE requests. Read more
§

fn apply(&mut self, op: Op<'_>) -> Result<Applied, Self::Error>

Applies a recorded operation, for example when replaying a journal. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more