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 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 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.