Skip to main content

ControlStore

Trait ControlStore 

Source
pub trait ControlStore: Send + Sync {
    // Required methods
    fn area_settings<'life0, 'life1, 'async_trait>(
        &'life0 self,
        partition: &'life1 PartitionId,
    ) -> Pin<Box<dyn Future<Output = Result<Option<AreaSettings>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn list_area_settings<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<AreaSettings>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn put_area_settings<'life0, 'async_trait>(
        &'life0 self,
        settings: AreaSettings,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn cursor<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        user: &'life1 str,
        viewer: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<AwayCursor>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn advance_cursor<'life0, 'async_trait>(
        &'life0 self,
        cursor: AwayCursor,
    ) -> Pin<Box<dyn Future<Output = Result<AwayCursor>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn update_area_settings<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        partition: &'life1 PartitionId,
        change: &'life2 (dyn for<'a> Fn(&'a mut AreaSettings) + Send + Sync),
    ) -> Pin<Box<dyn Future<Output = Result<AreaSettings>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Where the control plane keeps AreaSettings and AwayCursors (spec 3.3 §10 K3, K4).

MethodContract
area_settings, list_area_settingsOne area’s record, or every one ordered by partition id
put_area_settingsReplaces the area’s record
update_area_settingsChanges the area’s record with no other write in between, so concurrent changes all hold
cursorOne viewer’s cursor
advance_cursorStores the cursor unless the stored one is past its seq, and returns the stored one: a cursor never moves back

§Example

use adk_kernel::control::{AwayCursor, ControlStore, InMemoryControlStore};

let store = InMemoryControlStore::new();
let now = chrono::Utc::now();
store.advance_cursor(AwayCursor::new("ana", "home", 9, now)).await?;
let stored = store.advance_cursor(AwayCursor::new("ana", "home", 4, now)).await?;
assert_eq!(stored.seq, 9, "a cursor never moves back");

Required Methods§

Source

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

The settings changed for partition, or None.

§Errors

Returns KernelError::Store when the backend fails.

Source

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

Every area’s changed settings, ordered by partition id.

§Errors

Returns KernelError::Store when the backend fails.

Source

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

Replaces the changed settings of settings.partition.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn cursor<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, user: &'life1 str, viewer: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<AwayCursor>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

The cursor of viewer of user, or None before it first marks anything seen.

§Errors

Returns KernelError::Store when the backend fails.

Source

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

Stores cursor when the stored cursor of its viewer is at or before its seq, and returns the cursor stored after the call.

§Errors

Returns KernelError::Store when the backend fails.

Provided Methods§

Source

fn update_area_settings<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, partition: &'life1 PartitionId, change: &'life2 (dyn for<'a> Fn(&'a mut AreaSettings) + Send + Sync), ) -> Pin<Box<dyn Future<Output = Result<AreaSettings>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Applies change to the record of partition, an empty one when it has none, and stores it with no other write in between: when another write changed the record meanwhile, change is applied again to that one, so concurrent changes of different settings all hold (spec 3.3 §10 K3). Returns the record stored.

The default reads, applies and puts, which keeps that promise only for a store with one writer; every store of this crate overrides it.

§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§