RecordStore

Trait RecordStore 

Source
pub trait RecordStore:
    Send
    + Sync
    + Debug {
    // Required methods
    fn insert(&mut self, record: MemoryRecord) -> Result<RecordId>;
    fn get(&self, id: &RecordId) -> Option<MemoryRecord>;
    fn contains(&self, id: &RecordId) -> bool;
    fn update_stats(&mut self, id: &RecordId, outcome: f64) -> Result<()>;
    fn remove(&mut self, id: &RecordId) -> Result<bool>;
    fn len(&self) -> usize;
    fn clear(&mut self);
    fn ids(&self) -> Vec<RecordId> ;
    fn memory_usage(&self) -> usize;

    // Provided methods
    fn insert_batch(
        &mut self,
        records: Vec<MemoryRecord>,
    ) -> Result<Vec<RecordId>> { ... }
    fn get_batch(&self, ids: &[RecordId]) -> Vec<Option<MemoryRecord>> { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

Core trait for record storage.

All storage implementations must implement this trait. The trait enforces INV-001 (record immutability) by only allowing stats updates after insertion.

Required Methods§

Source

fn insert(&mut self, record: MemoryRecord) -> Result<RecordId>

Insert a new record.

§Errors

Returns error if record with same ID already exists.

Source

fn get(&self, id: &RecordId) -> Option<MemoryRecord>

Get a record by ID.

Source

fn contains(&self, id: &RecordId) -> bool

Check if a record exists.

Source

fn update_stats(&mut self, id: &RecordId, outcome: f64) -> Result<()>

Update the outcome statistics for a record.

This is the ONLY mutable operation allowed on a record after insertion (enforces INV-001).

§Arguments
  • id - Record ID
  • outcome - New outcome value to incorporate
Source

fn remove(&mut self, id: &RecordId) -> Result<bool>

Remove a record (marks as deleted, may not physically remove).

§Returns

true if record was found and removed.

Source

fn len(&self) -> usize

Number of records in the store.

Source

fn clear(&mut self)

Clear all records.

Source

fn ids(&self) -> Vec<RecordId>

Get all record IDs.

Source

fn memory_usage(&self) -> usize

Get memory usage estimate in bytes.

Provided Methods§

Source

fn insert_batch(&mut self, records: Vec<MemoryRecord>) -> Result<Vec<RecordId>>

Insert multiple records in batch.

Default implementation calls insert repeatedly.

Source

fn get_batch(&self, ids: &[RecordId]) -> Vec<Option<MemoryRecord>>

Get multiple records by ID.

Source

fn is_empty(&self) -> bool

Whether the store is empty.

Implementors§