Expand description
High-throughput local buffer for cloud sync — single-process by design, durability-configurable, optional performant encryption, at-least-once delivery.
Items are accumulated in memory, flushed as zstd-compressed CBOR batches
to seg_{start:012}_{end:012}.zst files, and deleted once the consumer
acknowledges receipt via SegmentBuffer::delete_acked.
The buffer is generic over any T: Serialize + DeserializeOwned + Clone + Send.
(No explicit 'static bound is required: DeserializeOwned already implies
it, since a borrowed type cannot satisfy for<'de> Deserialize<'de>.)
Crash recovery is filename-based: scanning the directory rebuilds head_seq
and next_seq without any WAL or metadata database.
§Example
use segment_buffer::{SegmentBuffer, SegmentConfig};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Clone)]
struct MyItem { id: u64 }
let buffer = SegmentBuffer::<MyItem>::open("/tmp/my-queue", SegmentConfig::default())?;
let seq = buffer.append(MyItem { id: 1 })?;
let items = buffer.read_from(0, 100)?;For the full README — install, quickstart, encryption, backpressure, comparison table, and performance notes — see the project README on GitHub or docs.rs.
Structs§
- Buffer
Stats - Point-in-time snapshot of buffer state, captured atomically under a single lock acquisition so all fields are mutually consistent.
- Cipher
Error - Error returned by
SegmentCipherimplementations. - Recovery
Report - Summary of the recovery scan performed by
SegmentBuffer::open. - Segment
Buffer - High-throughput local buffer for cloud sync, holding items of
Tin memory and spilling them to compressed segment files for at-least-once delivery to a cloud endpoint. - Segment
Config - Configuration knobs for
SegmentBuffer. - Segment
Config Builder - Ergonomic builder for
SegmentConfig. - Segment
Iter - Owned-item iterator over buffer contents, yielding
(seq, item)pairs.
Enums§
- Durability
Policy - Per-flush durability tradeoff between throughput and crash safety.
- Flush
Policy - When to auto-flush pending items from memory to a segment file.
- IoSite
- Which filesystem site an
SegmentError::Iofailure happened on. - Segment
Error - Errors produced by segment-buffer operations.
Traits§
- Segment
Cipher - Encrypts and decrypts segment file payloads.
Type Aliases§
- Result
- Result alias used throughout the crate.