Skip to main content

Crate delta_stream

Crate delta_stream 

Source
Expand description

DeltaStream is a state-aware synchronization library for realtime Rust applications.

It sends an initial snapshot and then compact state deltas when doing so is cheaper, while validating sequence/base-state relationships on the receiver. When the chain breaks, the receiver reports that recovery is required instead of applying an unsafe delta.

§Quick start

use delta_stream::{DeltaState, Publisher, Subscriber};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, DeltaState)]
struct GameState {
    x: i32,
    hp: u16,
}

let mut publisher = Publisher::<GameState>::new();
let mut subscriber = Subscriber::<GameState>::new();

let bytes = publisher.encode(&GameState { x: 10, hp: 100 })?;
subscriber.receive(&bytes)?;

assert_eq!(subscriber.state().map(|state| state.hp), Some(100));

§Synchronization flow

Application state
    -> Publisher
    -> snapshot or delta packet
    -> serialized bytes
    -> any byte-capable transport
    -> received bytes
    -> Subscriber
    -> validated synchronized state

§Transport model

DeltaStream produces and consumes Packet values. A transport is responsible for moving the serialized packet bytes between peers. Optional adapters are available for PubNub, WebSocket, MQTT, and NATS behind Cargo features.

Re-exports§

pub use api::Publisher;
pub use api::PublisherBuilder;
pub use api::StatePublisher;
pub use api::StateSubscriber;
pub use api::Subscriber;
pub use error::DeltaError;
pub use packet::DecodeConfig;
pub use packet::Packet;
pub use packet::PacketKind;
pub use packet::MAX_LOGICAL_PAYLOAD;
pub use packet::MAX_WIRE_PAYLOAD;
pub use packet::WIRE_VERSION;
pub use partial_repair::ChunkManifest;
pub use partial_repair::ChunkPatch;
pub use partial_repair::PartialRepair;
pub use runtime::backpressure_decision;
pub use runtime::BackpressureDecision;
pub use runtime::RuntimeLimits;
pub use runtime::RuntimeMetrics;
pub use schema::DeltaState;

Modules§

advanced
Lower-level protocol and tuning types for advanced integrations.
api
crdt
Optional state-based CRDTs for multi-writer replicated values.
error
packet
partial_repair
prelude
Common imports for application code.
recovery_history
reorder
runtime
schema
session
transport

Enums§

Apply
Result of applying a packet to a subscriber.

Derive Macros§

DeltaState