pub trait Session: Send {
// Required methods
fn call<'a>(
&'a mut self,
method: &'a str,
params: Payload,
) -> BoxFut<'a, Result<Payload, RpcError>>;
fn write<'a>(
&'a mut self,
topic: &'a str,
payload: Payload,
) -> BoxFut<'a, Result<(), RpcError>>;
// Provided methods
fn subscribe<'a>(
&'a mut self,
topic: &'a str,
) -> BoxFut<'a, Result<BoxStream<'static, SubUpdate>, RpcError>> { ... }
fn snapshots(&mut self, topic: &str) -> Vec<(String, Payload)> { ... }
}Expand description
The per-connection session: serves calls, subscriptions, and writes for one
accepted Connection. The engine owns the Box<dyn Session> and threads
&mut self into each method, so it can hold per-connection state without a
lock; the shared, immutable role stays on Dispatch.
Required Methods§
Provided Methods§
Sourcefn subscribe<'a>(
&'a mut self,
topic: &'a str,
) -> BoxFut<'a, Result<BoxStream<'static, SubUpdate>, RpcError>>
fn subscribe<'a>( &'a mut self, topic: &'a str, ) -> BoxFut<'a, Result<BoxStream<'static, SubUpdate>, RpcError>>
Open a subscription yielding many SubUpdates. The stream is 'static
(it captures cloned handles) so it outlives the &mut borrow and lives in
the engine. Async so a connector can await per-operation authorization.
Defaulted to RpcError::NotFound for dispatches with no streaming.
Sourcefn snapshots(&mut self, topic: &str) -> Vec<(String, Payload)>
fn snapshots(&mut self, topic: &str) -> Vec<(String, Payload)>
Late-join snapshots: one (topic, value) per record covered by topic
(several for a wildcard subscription), each emitted as an
Outbound::Snapshot right after a successful
subscribe and before the first event. Defaulted
to empty (no snapshots).
The engine numbers the burst 1..=N and starts the event stream at
N + 1, so a snapshot dropped in transit shows up as
SubUpdate::skipped on the next delivered update.
The burst’s last snapshot is flagged and reaches the subscriber as the
one update with SubUpdate::snapshot_end set, carrying the burst’s
whole loss; the client engine reserves a sink slot so it survives a slow
consumer.
Do not block on that flag. It is absent when topic matches no
records, and when the final snapshot fails to encode or its frame is
rejected — the flag rides that frame. Loss accounting survives all of
these; only the end-of-burst signal is lost.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".