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:
Database::get_store_viewer: For read-only access to the current merged state.Transaction::get_store: For staging modifications within a transaction.
Store types must also implement Registered to provide their type identifier.
Required Associated Types§
Required Methods§
Sourcefn 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 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- TheTransactionthisStoreinstance will read from and potentially write to.subtree_name- The name identifying this specific data partition within theDatabase.
Sourcefn transaction(&self) -> &Transaction
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§
Sourcefn default_config() -> Doc
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());Sourcefn 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 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:
- Creates the Store using
Self::new() - Registers it in
_indexwithSelf::type_id()andSelf::default_config()
Store implementations can override this to customize initialization behavior.
§Arguments
txn- TheTransactionthisStoreinstance will operate within.subtree_name- The name identifying this specific data partition.
§Returns
A Result<Self> containing the initialized Store.
Sourcefn 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 get_config<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Doc>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn local_data(&self) -> Result<Option<Self::Data>>
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.