Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica

Store

Trait Store 

Source
pub trait Store:
    Sized
    + Registered
    + Send
    + Sync {
    type Data: CRDT;

    // Required methods
    fn new<'life0, 'async_trait>(
        txn: &'life0 Transaction,
        subtree_name: String,
    ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn name(&self) -> &str;
    fn transaction(&self) -> &Transaction;

    // Provided methods
    fn default_config() -> Doc { ... }
    fn init<'life0, 'async_trait>(
        txn: &'life0 Transaction,
        subtree_name: String,
    ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn get_config<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Doc>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn set_config<'life0, 'async_trait>(
        &'life0 self,
        config: Doc,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn get_height_strategy<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Option<HeightStrategy>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn set_height_strategy<'life0, 'async_trait>(
        &'life0 self,
        strategy: Option<HeightStrategy>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn local_data(&self) -> Result<Option<Self::Data>> { ... }
}
Expand description

A trait representing a named, CRDT-based data structure within a Database.

Store implementations define how data within a specific named partition of a Database is structured, accessed, and modified. They work in conjunction with a Transaction to stage changes before committing them as a single Entry.

Users typically interact with Store implementations obtained either via:

  1. Database::get_store_viewer: For read-only access to the current merged state.
  2. Transaction::get_store: For staging modifications within a transaction.

Store types must also implement Registered to provide their type identifier.

Required Associated Types§

Source

type Data: CRDT

The CRDT data type used for local (staged) data in this store.

This is the type stored within each individual Entry.

Required Methods§

Source

fn new<'life0, 'async_trait>( txn: &'life0 Transaction, subtree_name: String, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Creates a new Store handle associated with a specific transaction.

This constructor is typically called internally by Transaction::get_store or Database::get_store_viewer. The resulting Store instance provides methods to interact with the data of the specified subtree_name, potentially staging changes within the provided txn.

§Arguments
  • txn - The Transaction this Store instance will read from and potentially write to.
  • subtree_name - The name identifying this specific data partition within the Database.
Source

fn name(&self) -> &str

Returns the name of this subtree.

Source

fn transaction(&self) -> &Transaction

Returns a reference to the transaction this Store is associated with.

This is used by the default implementations of init(), get_config(), and set_config() to access the index store.

Provided Methods§

Source

fn default_config() -> Doc

Returns the default configuration for this Store type as a Doc.

This configuration is stored in the _index subtree when a new subtree is first created. The Store implementation owns the format and interpretation of this configuration data.

The default implementation returns an empty Doc. Store implementations that require specific configuration should override this method.

§Examples
let config = DocStore::default_config();
assert!(config.is_empty());
Source

fn init<'life0, 'async_trait>( txn: &'life0 Transaction, subtree_name: String, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Initializes a new subtree and registers it in the _index.

This method is called by Transaction::get_store() when accessing a subtree that doesn’t yet exist in the _index. It creates the Store and registers its type and default configuration in the index.

The default implementation:

  1. Creates the Store using Self::new()
  2. Registers it in _index with Self::type_id() and Self::default_config()

Store implementations can override this to customize initialization behavior.

§Arguments
  • txn - The Transaction this Store instance will operate within.
  • subtree_name - The name identifying this specific data partition.
§Returns

A Result<Self> containing the initialized Store.

Source

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

Gets the current configuration for this Store from the _index subtree.

§Returns

A Result<Doc> containing the configuration document.

§Errors

Returns an error if the subtree is not registered in _index.

Source

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

Sets the configuration for this Store in the _index subtree.

This method updates the _index with the Store’s type ID and the provided configuration. It’s called automatically by init() and can be used to update configuration during a transaction.

§Arguments
  • config - The configuration document to store.
§Returns

A Result<()> indicating success or failure.

Source

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

Gets the height strategy for this Store from the _index subtree.

Returns None if no strategy is set (meaning the subtree inherits from the database-level height strategy).

§Returns

A Result<Option<HeightStrategy>> containing the strategy if set.

§Errors

Returns an error if the subtree is not registered in _index.

Source

fn set_height_strategy<'life0, 'async_trait>( &'life0 self, strategy: Option<HeightStrategy>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sets the height strategy for this Store in the _index subtree.

Pass None to inherit from the database-level strategy, or Some(strategy) for independent height calculation.

§Arguments
  • strategy - The height strategy to use, or None for inheritance.
§Returns

A Result<()> indicating success or failure.

§Errors

Returns an error if the subtree is not registered in _index.

Source

fn local_data(&self) -> Result<Option<Self::Data>>

Returns the local (staged) data for this store from the current transaction.

This is a convenience method that retrieves data staged in the transaction for this store’s subtree. Returns Ok(None) if no data has been staged.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Store for DocStore

Source§

impl Store for YDoc

Source§

impl<S: Store> Store for PasswordStore<S>

Source§

type Data = <S as Store>::Data

Source§

impl<T> Store for Table<T>
where T: Serialize + for<'de> Deserialize<'de> + Clone + Send + Sync,