pub trait AttributeStorage<A: AttributeBind>: UnknownAttributeStorage {
// Required methods
fn read(
&self,
trans: &mut Transaction,
id: A::IdentifierType,
) -> StmResult<Option<A>>;
fn write(
&self,
trans: &mut Transaction,
id: A::IdentifierType,
val: A,
) -> StmResult<Option<A>>;
fn remove(
&self,
trans: &mut Transaction,
id: A::IdentifierType,
) -> StmResult<Option<A>>;
fn force_write(&self, id: A::IdentifierType, val: A) -> Option<A>;
// Provided methods
fn force_read(&self, id: A::IdentifierType) -> Option<A> { ... }
fn force_remove(&self, id: A::IdentifierType) -> Option<A> { ... }
}
Expand description
Common trait implemented by generic attribute storages.
This trait contain attribute-specific methods.
The documentation of this trait describe the behavior each function & method should have. “ID” and “index” are used interchangeably.
§Note on force / regular semantics
We define two variants of read / write / remove methods: force
and regular. Their goal is to
provide different degrees of control vs convenience when using these operations. Documentation
of each method shortly explains their individual quirks, below is a table summarizing the
differences:
variant | description |
---|---|
regular | regular impl, which will fail if the transaction fails |
force | convenience impl, which wraps the regular impl in a transaction that retries until success |
Required Methods§
Sourcefn read(
&self,
trans: &mut Transaction,
id: A::IdentifierType,
) -> StmResult<Option<A>>
fn read( &self, trans: &mut Transaction, id: A::IdentifierType, ) -> StmResult<Option<A>>
Read the value of an element at a given index.
§Arguments
trans: &mut Transaction
– Transaction used for synchronization.index: A::IdentifierType
– Cell index.
§Return / Errors
This method is meant to be called in a context where the returned Result
is used to
validate the transaction passed as argument. The result should not be processed manually,
only used via the ?
operator.
§Panics
The method:
- should panic if the index lands out of bounds
- may panic if the index cannot be converted to
usize
Sourcefn write(
&self,
trans: &mut Transaction,
id: A::IdentifierType,
val: A,
) -> StmResult<Option<A>>
fn write( &self, trans: &mut Transaction, id: A::IdentifierType, val: A, ) -> StmResult<Option<A>>
Write the value of an element at a given index and return the old value.
§Arguments
trans: &mut Transaction
– Transaction used for synchronization.index: A::IdentifierType
– Cell index.val: A
– Attribute value.
§Return / Errors
This method is meant to be called in a context where the returned Result
is used to
validate the transaction passed as argument. The result should not be processed manually,
only used via the ?
operator.
§Panics
The method:
- should panic if the index lands out of bounds
- may panic if the index cannot be converted to
usize
Sourcefn remove(
&self,
trans: &mut Transaction,
id: A::IdentifierType,
) -> StmResult<Option<A>>
fn remove( &self, trans: &mut Transaction, id: A::IdentifierType, ) -> StmResult<Option<A>>
Remove the value at a given index and return it.
§Arguments
trans: &mut Transaction
– Transaction used for synchronization.index: A::IdentifierType
– Cell index.
§Return / Errors
This method is meant to be called in a context where the returned Result
is used to
validate the transaction passed as argument. The result should not be processed manually,
only used via the ?
operator.
§Panics
The method:
- should panic if the index lands out of bounds
- may panic if the index cannot be converted to
usize
Sourcefn force_write(&self, id: A::IdentifierType, val: A) -> Option<A>
fn force_write(&self, id: A::IdentifierType, val: A) -> Option<A>
Write the value of an element at a given index and return the old value.
This variant is equivalent to write
, but internally uses a transaction that will be
retried until validated.
Provided Methods§
Sourcefn force_read(&self, id: A::IdentifierType) -> Option<A>
fn force_read(&self, id: A::IdentifierType) -> Option<A>
Read the value of an element at a given index.
This variant is equivalent to read
, but internally uses a transaction that will be
retried until validated.
Sourcefn force_remove(&self, id: A::IdentifierType) -> Option<A>
fn force_remove(&self, id: A::IdentifierType) -> Option<A>
Remove the value at a given index and return it.
This variant is equivalent to remove
, but internally uses a transaction that will be
retried until validated.