pub struct SessionRuntime { /* private fields */ }Expand description
The session-type runtime cursor + credit window.
Held by each side of a connection — the server runtime is initialised with the server-role type, the client with the dual. Every transition is local: there is no cross-process synchronisation here; the carrier delivers frames in order and the two cursors stay in lock step because they were initialised from a duality-checked pair.
Serialize + Deserialize — §Fase 41.g sealed-snapshot resume. The
serialised form is a stable JSON object containing the schema (so
resume can verify the protocol hasn’t been swapped), the residual
cursor, and the live credit window. Encoded once via Self::seal
into the AAD-bound cognitive_states ciphertext; decoded by
Self::resume after the §40.k EnvelopeEncryption::decrypt verifies
the (tenant, session, flow) binding.
Implementations§
Source§impl SessionRuntime
impl SessionRuntime
Sourcepub fn new(schema: SessionType, budget: Option<u64>) -> Self
pub fn new(schema: SessionType, budget: Option<u64>) -> Self
Create a runtime for the given role’s session type. budget
mirrors the socket’s credit(k); pass None for the unbounded
fragment (statically equivalent to omitting backpressure:).
Sourcepub fn schema(&self) -> &SessionType
pub fn schema(&self) -> &SessionType
The original session type — useful for error messages and logs.
Sourcepub fn cursor(&self) -> &SessionType
pub fn cursor(&self) -> &SessionType
The current residual cursor — always head-unfolded.
Sourcepub fn credit(&self) -> Option<CreditWindow>
pub fn credit(&self) -> Option<CreditWindow>
The dynamic credit window snapshot (or None for the unbounded
fragment).
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
true once the cursor reaches end — both sides should now close
the carrier cleanly. The runtime rejects further actions after
this point with ProtocolError::AlreadyComplete.
Sourcepub fn seal(&self) -> Option<SealedRuntime>
pub fn seal(&self) -> Option<SealedRuntime>
Serialise the live runtime state into a stable JSON envelope —
the plaintext the §40.t cognitive_states AAD-bound ciphertext
wraps. Carries the schema (so resume can verify the protocol
hasn’t been swapped under the connection), the residual cursor,
and the live credit window snapshot.
Symmetric with Self::resume: runtime.seal() then
SessionRuntime::resume(sealed, declared_schema) round-trips when
the declared schema matches.
Returns None if and only if the cursor is already at End — a
completed dialogue has no residual to seal, so no snapshot is
issued (the caller should evict() the prior snapshot instead).
Sourcepub fn resume(
sealed: SealedRuntime,
declared_schema: &SessionType,
) -> Result<Self, ResumeError>
pub fn resume( sealed: SealedRuntime, declared_schema: &SessionType, ) -> Result<Self, ResumeError>
Reconstruct a SessionRuntime from a sealed snapshot, validating
the schema matches what the route declares now (defence against
protocol-swap attacks where an attacker reuses a sealed snapshot
against a different socket whose declaration drifted).
On success the returned runtime resumes from the exact cursor + credit window the disconnected one left behind. The carrier driver then runs the producer/consumer loop as usual.
Sourcepub fn try_send(&mut self, got: &str) -> Result<(), ProtocolError>
pub fn try_send(&mut self, got: &str) -> Result<(), ProtocolError>
Producer step !A.S → S. Succeeds iff:
- the cursor is
Send { payload, … }withpayload == got; - the credit window (if any) has
available > 0— otherwise the §41.c “no rule at n=0” axiom fires. On success the cursor advances (unfolded) and one credit is consumed (when the window is present).
Sourcepub fn try_recv(&mut self, got: &str) -> Result<(), ProtocolError>
pub fn try_recv(&mut self, got: &str) -> Result<(), ProtocolError>
Consumer step ?A.S → S. The peer just produced an !A.S frame.
Symmetric to [try_send] — payload must match, the cursor advances,
and one credit is refilled (if a window is present).
Sourcepub fn try_select(&mut self, label: &str) -> Result<(), ProtocolError>
pub fn try_select(&mut self, label: &str) -> Result<(), ProtocolError>
Internal choice (⊕) — we select the labelled arm. Cursor must
be Select { arms } containing label; on success the cursor
advances into that arm’s continuation.
Sourcepub fn try_offer(&mut self, label: &str) -> Result<(), ProtocolError>
pub fn try_offer(&mut self, label: &str) -> Result<(), ProtocolError>
External choice (&) — the peer selected this label; we accept.
Cursor must be Branch { arms } containing label.
Sourcepub fn try_end(&mut self) -> Result<(), ProtocolError>
pub fn try_end(&mut self) -> Result<(), ProtocolError>
end step — terminates the dialogue. Cursor must already be
End; otherwise the peer is signalling termination mid-protocol.
Trait Implementations§
Source§impl Clone for SessionRuntime
impl Clone for SessionRuntime
Source§fn clone(&self) -> SessionRuntime
fn clone(&self) -> SessionRuntime
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SessionRuntime
impl Debug for SessionRuntime
Source§impl<'de> Deserialize<'de> for SessionRuntime
impl<'de> Deserialize<'de> for SessionRuntime
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for SessionRuntime
impl RefUnwindSafe for SessionRuntime
impl Send for SessionRuntime
impl Sync for SessionRuntime
impl Unpin for SessionRuntime
impl UnsafeUnpin for SessionRuntime
impl UnwindSafe for SessionRuntime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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