Skip to main content

CharterStore

Trait CharterStore 

Source
pub trait CharterStore: Send + Sync {
    // Required methods
    fn append<'life0, 'async_trait>(
        &'life0 self,
        version: CharterVersion,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn current<'life0, 'async_trait>(
        &'life0 self,
        site: Uuid,
    ) -> Pin<Box<dyn Future<Output = Result<Option<CharterVersion>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn history<'life0, 'async_trait>(
        &'life0 self,
        site: Uuid,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<CharterVersion>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get<'life0, 'async_trait>(
        &'life0 self,
        site: Uuid,
        version: u32,
    ) -> Pin<Box<dyn Future<Output = Result<Option<CharterVersion>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn commit<'life0, 'async_trait>(
        &'life0 self,
        draft: Charter,
        decision: CommitDecision,
    ) -> Pin<Box<dyn Future<Output = Result<CharterVersion>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Every committed version of every site’s charter (spec 3.5 §7.11), append-only, on in-memory, SQLite, PostgreSQL and Redis.

commit is the only way a version takes effect; it checks the draft and the decision and calls append, which backends implement as a compare-and-set on the site’s latest version.

§Example

ⓘ
let committed = store.commit(draft, decision).await?;
assert_eq!(store.current(committed.site()).await?.unwrap().version(), committed.version());

Required Methods§

Source

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

Appends version when its number is one past the site’s latest committed version (1 for a site with none); false, writing nothing, otherwise.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn current<'life0, 'async_trait>( &'life0 self, site: Uuid, ) -> Pin<Box<dyn Future<Output = Result<Option<CharterVersion>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

The site’s version in force: its latest, or None before the first commit.

§Errors

Returns KernelError::Store when the backend fails.

Source

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

Every committed version of the site, oldest first.

§Errors

Returns KernelError::Store when the backend fails.

Source

fn get<'life0, 'async_trait>( &'life0 self, site: Uuid, version: u32, ) -> Pin<Box<dyn Future<Output = Result<Option<CharterVersion>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Version version of the site, or None.

§Errors

Returns KernelError::Store when the backend fails.

Provided Methods§

Source

fn commit<'life0, 'async_trait>( &'life0 self, draft: Charter, decision: CommitDecision, ) -> Pin<Box<dyn Future<Output = Result<CharterVersion>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Commits draft by decision as the site’s next version (spec 3.5 §7.6, A-I23).

The draft must pass Charter::validate() (A-I14: no target without a baseline), and no role in its governance may be held by an agent. The decision must satisfy the approval chain for CHARTER_ACTION of the charter in force — or, for a site’s first charter, of the draft — by distinct people (check_chain), so a draft cannot loosen the chain that approves it. The committed version is the next number, signed with the decision: its id, the first owner’s approval, the signed note and the time.

§Errors

Returns KernelError::Config for a draft that fails validation or names another site, KernelError::Unauthorized for a decision that does not satisfy the chain, an AdkError conflict when another commit took the version first, or a store error.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§