pub struct Transaction { /* private fields */ }Expand description
A batch of edits, validated together and applied as a unit.
Opened against a model snapshot and carrying that snapshot’s revision, so a commit against a model that has since changed is refused rather than applied to state the caller never saw.
Implementations§
Source§impl Transaction
impl Transaction
Sourcepub fn edits(&self) -> &[Edit]
pub fn edits(&self) -> &[Edit]
The staged edits, in the order they were added. Truncations are not
edits: see Transaction::truncations.
Sourcepub fn create(&mut self, entity: Entity) -> EntityId
pub fn create(&mut self, entity: Entity) -> EntityId
Stage a new entity, returning the id reserved for it.
The id is allocated from the transaction, not the model, so several creates in one batch cannot collide and the caller can reference a newly created entity from another edit in the same transaction before anything is written.
Sourcepub fn stage(&mut self, edit: Edit) -> &mut Self
pub fn stage(&mut self, edit: Edit) -> &mut Self
Stage an already-constructed edit.
Transaction::create allocates ids and is what an author should
use. This exists for replaying a batch that was built elsewhere –
deserialized, or produced by another process – where the edit list
is data rather than a sequence of calls. Preflight checks it exactly
the same way, so a replayed batch cannot bypass validation.
Sourcepub fn set_attribute(
&mut self,
id: EntityId,
slot: usize,
value: Value,
) -> &mut Self
pub fn set_attribute( &mut self, id: EntityId, slot: usize, value: Value, ) -> &mut Self
Stage an attribute write.
Sourcepub fn retype(
&mut self,
id: EntityId,
type_name: impl Into<Arc<str>>,
) -> &mut Self
pub fn retype( &mut self, id: EntityId, type_name: impl Into<Arc<str>>, ) -> &mut Self
Stage a type change.
Sourcepub fn set_header(&mut self, header: Header) -> &mut Self
pub fn set_header(&mut self, header: Header) -> &mut Self
Stage a replacement of the file header, applied after the edits.
Sourcepub fn truncate(&mut self, id: EntityId, len: usize) -> &mut Self
pub fn truncate(&mut self, id: EntityId, len: usize) -> &mut Self
Stage shortening id’s record to its first len attributes, applied
after every edit and before the header. Staging id again replaces
the length.
The record may be one the batch creates. A len at or past the
record’s length at that point drops nothing. A Edit::SetAttribute
at a slot of len or more is refused
(Conflict::WriteBeyondTruncation); references held only in dropped
slots do not keep a removed entity alive.
Sourcepub fn truncations(&self) -> impl Iterator<Item = (EntityId, usize)> + '_
pub fn truncations(&self) -> impl Iterator<Item = (EntityId, usize)> + '_
The staged truncations as (id, len), in ascending id.
Sourcepub fn preflight(&self, model: &Model) -> Vec<Conflict>
pub fn preflight(&self, model: &Model) -> Vec<Conflict>
Check every edit without touching the model.
Returns every conflict found rather than the first: an author fixing a batch wants the whole list, and stopping at the first turns one review into N round trips.
Conflicts are ordered by the edit that produced them, so the report reads in the order the caller wrote the batch.
Sourcepub fn commit(self, model: &mut Model) -> Result<Applied, Vec<Conflict>>
pub fn commit(self, model: &mut Model) -> Result<Applied, Vec<Conflict>>
Validate and apply, or report every conflict and change nothing.
On Err the model is untouched: preflight runs to completion before
the first write, so a rejected transaction cannot leave partial state.
Sourcepub fn commit_reversible(
self,
model: &mut Model,
) -> Result<(Applied, Inverse), Vec<Conflict>>
pub fn commit_reversible( self, model: &mut Model, ) -> Result<(Applied, Inverse), Vec<Conflict>>
Transaction::commit, also returning the Inverse that restores
the model exactly. A refused commit changes nothing and returns the
conflicts only.
Trait Implementations§
Source§impl Clone for Transaction
impl Clone for Transaction
Source§fn clone(&self) -> Transaction
fn clone(&self) -> Transaction
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more