Skip to main content

LedgerStore

Trait LedgerStore 

Source
pub trait LedgerStore: Send + Sync {
    // Required methods
    fn append<'life0, 'async_trait>(
        &'life0 self,
        entry: LedgerEntry,
    ) -> Pin<Box<dyn Future<Output = Result<LedgerEntry>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn list<'life0, 'life1, 'async_trait>(
        &'life0 self,
        query: &'life1 LedgerQuery,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<LedgerEntry>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn put_observation<'life0, 'async_trait>(
        &'life0 self,
        observation: Observation,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn observations<'life0, 'life1, 'async_trait>(
        &'life0 self,
        query: &'life1 ObservationQuery,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Observation>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn pass_state<'life0, 'life1, 'async_trait>(
        &'life0 self,
        partition: &'life1 PartitionId,
    ) -> Pin<Box<dyn Future<Output = Result<Option<PassState>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn pass_states<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<PassState>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn put_pass_state<'life0, 'async_trait>(
        &'life0 self,
        state: PassState,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

The kernel’s ledger, observations and baseline pass state (spec 3.2 §7.10, §13 Q8).

The ledger is append-only: rows are added and read, never changed. Observations are replaced by id, so two replicas recording one observation store one; the pass state is one record per partition.

§Example

use std::sync::Arc;
use adk_kernel::proc::{Activity, InMemoryLedgerStore, Ledger, LedgerKey, LedgerKind, LedgerQuery, LedgerStore};

let store = InMemoryLedgerStore::new();
let ledger = Ledger::new(Arc::new(InMemoryLedgerStore::new()), LedgerKey::from_bytes([1; 32]));
let first = store.append(ledger.entry(Activity::new(LedgerKind::Wake, "kernel"))?).await?;
let second = store.append(ledger.entry(Activity::new(LedgerKind::Intent, "harness"))?).await?;
assert!(second.seq > first.seq);
let after = store.list(&LedgerQuery::default().after(first.seq)).await?;
assert_eq!(after, [second]);

Required Methods§

Source

fn append<'life0, 'async_trait>( &'life0 self, entry: LedgerEntry, ) -> Pin<Box<dyn Future<Output = Result<LedgerEntry>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Appends entry with the next sequence number and returns it as stored; entry.seq is ignored.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn list<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 LedgerQuery, ) -> Pin<Box<dyn Future<Output = Result<Vec<LedgerEntry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The rows query selects, in sequence order, at most query.limit.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn put_observation<'life0, 'async_trait>( &'life0 self, observation: Observation, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Inserts observation, or replaces the one with the same id.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn observations<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 ObservationQuery, ) -> Pin<Box<dyn Future<Output = Result<Vec<Observation>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The observations query selects, newest day first, then by id.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn pass_state<'life0, 'life1, 'async_trait>( &'life0 self, partition: &'life1 PartitionId, ) -> Pin<Box<dyn Future<Output = Result<Option<PassState>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The pass state of partition, or None before its first pass.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn pass_states<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<PassState>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Every partition’s pass state, by partition.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn put_pass_state<'life0, 'async_trait>( &'life0 self, state: PassState, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores state as its partition’s pass state.

§Errors

Returns KernelError::Store when the backend fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§