pub struct DiskStore<T: DataPoint> { /* private fields */ }Expand description
Generic fixed-record binary writer + reader for T: DataPoint.
Layout under <storage_root>/<kind-slug>/<exchange>/<account>/<symbol>/<YYYY-MM-DD>.dat:
.dat: append-only,T::RECORD_SIZEbytes per record (little-endian)..idx: sparse[u64 ts_ms, u64 file_offset]every N records..blob: append-only UTF-8 byte stream (only for types whereDataPoint::blob_pointer_offsetisSome(_)). Each header’s trailing(blob_offset: u64, blob_len: u32)references a slice in this file.
UTC day rotation. Idx interval is configurable (default 1024).
Implementations§
Source§impl<T: DataPoint> DiskStore<T>
impl<T: DataPoint> DiskStore<T>
Sourcepub async fn new(storage_root: &Path, key: SeriesKey) -> Result<Self>
pub async fn new(storage_root: &Path, key: SeriesKey) -> Result<Self>
Open (or create) a DiskStore. async to match the wasm32 sibling API
— the actual work is synchronous; the async wrapper is zero-cost.
Sourcepub async fn with_idx_every(
storage_root: &Path,
key: SeriesKey,
idx_every: u32,
) -> Result<Self>
pub async fn with_idx_every( storage_root: &Path, key: SeriesKey, idx_every: u32, ) -> Result<Self>
Like new but with a custom idx sparsity factor.
async to match the wasm32 sibling API — synchronous internally.
Sourcepub fn append(&mut self, point: &T) -> Result<()>
pub fn append(&mut self, point: &T) -> Result<()>
Append one record, possibly rotating to a new UTC day file.
Write order: blob bytes first, header second. Crash mid-blob leaves orphan bytes (no header references them); crash between blob and header still references valid blob range only if the header itself was flushed — partial header is detected on read.
Sourcepub fn append_batch(&mut self, points: &[T]) -> Result<()>
pub fn append_batch(&mut self, points: &[T]) -> Result<()>
Append many points (batch). Same per-record semantics.
Sourcepub async fn flush(&mut self) -> Result<()>
pub async fn flush(&mut self) -> Result<()>
Flush OS write buffers. async to match the wasm32 sibling API —
synchronous internally. The work completes before the future resolves.
Sourcepub async fn read_tail(&self, limit: usize) -> Result<Vec<T>>
pub async fn read_tail(&self, limit: usize) -> Result<Vec<T>>
Read up to limit most-recent records from the current day’s .dat.
Used for warm-start. Returns oldest → newest order.
For types with blob_pointer_offset(), opens the .blob file
read-only and reconstructs string fields via DataPoint::decode_blob.
async to match the wasm32 sibling API — synchronous internally.