Skip to main content

StateSubscriber

Struct StateSubscriber 

Source
pub struct StateSubscriber<T: DeltaState> { /* private fields */ }
Expand description

Receives and applies DeltaStream packets for one application-state stream.

A subscriber owns the receiving side of a stream. The usual flow is:

serialized bytes -> Subscriber -> validated synchronized state.

It validates schema identity, sequence/base-state relationships, duplicate and stale packets, packet integrity, and decompression limits before committing a new state.

Implementations§

Source§

impl<T: DeltaState> StateSubscriber<T>

Source

pub fn new() -> Self

Creates an empty subscriber.

Source

pub fn with_decode_config(decode_config: DecodeConfig) -> Self

Creates an empty subscriber with explicit packet decoding limits.

Source

pub fn receive( &mut self, bytes: &[u8], ) -> Result<GenericApplyResult<T>, DeltaError>

Receives transport bytes, decodes a packet, and applies it.

This is the high-level receiving path. It parses bytes with Packet::from_bytes_with_config, validates packet integrity, decompresses within configured limits when needed, and then applies the packet with the same state-chain logic as Subscriber::apply. It may apply a new state, report a duplicate, or request a snapshot when a gap or incompatible base is detected.

Source

pub fn apply( &mut self, packet: Packet, ) -> Result<GenericApplyResult<T>, DeltaError>

Applies a snapshot or delta packet.

Snapshots establish or restore state. Deltas are committed only when the local sequence and base-state hash match the packet metadata. Rejected packets do not mutate the subscriber state.

Source

pub fn apply_with_migrations( &mut self, packet: Packet, migrations: &MigrationRegistry, ) -> Result<GenericApplyResult<T>, DeltaError>

Applies a packet and allows registered snapshot migrations when schemas differ.

Source

pub fn state(&self) -> Option<&T>

Returns the last synchronized state.

Source

pub fn sequence(&self) -> Option<u64>

Returns the last applied sequence.

Source

pub fn reset(&mut self)

Clears local state and sequence tracking.

Trait Implementations§

Source§

impl<T: DeltaState> Default for StateSubscriber<T>

Source§

fn default() -> Self

Returns the “default value” for a type. 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
Source§

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

Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

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, !>

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

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

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