Skip to main content

Transaction

Struct Transaction 

pub struct Transaction<'a> { /* private fields */ }
Expand description

A transaction on a document. Transactions group operations into a single change so that no other operations can happen in-between.

Created from Automerge::transaction().

§Drop

This transaction should be manually committed or rolled back. If not done manually then it will be rolled back when it is dropped. This is to prevent the document being in an unsafe intermediate state. This is consistent with ? error handling.

Implementations§

§

impl<'a> Transaction<'a>

pub fn hash_for_opid(&self, opid: &ExId) -> Option<ChangeHash>

Get the hash of the change that contains the given opid.

Returns none if the opid:

  • is the root object id
  • does not exist in this document
  • is for an operation in this transaction
§

impl Transaction<'_>

pub fn get_heads(&self) -> Vec<ChangeHash>

Get the heads of the document before this transaction was started.

pub fn commit(self) -> (Option<ChangeHash>, PatchLog)

Commit the operations performed in this transaction, returning the hashes corresponding to the new heads.

pub fn commit_with( self, options: CommitOptions, ) -> (Option<ChangeHash>, PatchLog)

Commit the operations in this transaction with some options.

let mut doc = Automerge::new();
let mut tx = doc.transaction();
tx.put_object(ROOT, "todos", ObjType::List).unwrap();
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() as
i64;
tx.commit_with(CommitOptions::default().with_message("Create todos list").with_time(now));

pub fn rollback(self) -> usize

Undo the operations added in this transaction, returning the number of cancelled operations.

Trait Implementations§

§

impl<'a> Debug for Transaction<'a>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Drop for Transaction<'_>

§

fn drop(&mut self)

If a transaction is not commited or rolled back manually then it can leave the document in an intermediate state. This defaults to rolling back the transaction to be compatible with ? error returning before reaching a call to Self::commit().

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
§

impl ReadDoc for Transaction<'_>

§

fn keys<O>(&self, obj: O) -> Keys<'_> ⓘ
where O: AsRef<ExId>,

Get the keys of the object obj. Read more
§

fn keys_at<O>(&self, obj: O, heads: &[ChangeHash]) -> Keys<'_> ⓘ
where O: AsRef<ExId>,

Get the keys of the object obj as at heads Read more
§

fn iter_at<O>(&self, obj: O, heads: Option<&[ChangeHash]>) -> DocIter<'_> ⓘ
where O: AsRef<ExId>,

Iterate over the object obj as at heads Read more
§

fn map_range<'b, O, R>(&'b self, obj: O, range: R) -> MapRange<'b> ⓘ
where O: AsRef<ExId>, R: RangeBounds<String> + 'b,

Iterate over the keys and values of the map obj in the given range. Read more
§

fn map_range_at<'b, O, R>( &'b self, obj: O, range: R, heads: &[ChangeHash], ) -> MapRange<'b> ⓘ
where O: AsRef<ExId>, R: RangeBounds<String> + 'b,

Iterate over the keys and values of the map obj in the given range as at heads Read more
§

fn list_range<O, R>(&self, obj: O, range: R) -> ListRange<'_> ⓘ
where O: AsRef<ExId>, R: RangeBounds<usize>,

Iterate over the indexes and values of the list or text obj in the given range. Read more
§

fn list_range_at<O, R>( &self, obj: O, range: R, heads: &[ChangeHash], ) -> ListRange<'_> ⓘ
where O: AsRef<ExId>, R: RangeBounds<usize>,

Iterate over the indexes and values of the list or text obj in the given range as at heads Read more
§

fn values<O>(&self, obj: O) -> Values<'_> ⓘ
where O: AsRef<ExId>,

Iterate over the values in a map, list, or text object Read more
§

fn values_at<O>(&self, obj: O, heads: &[ChangeHash]) -> Values<'_> ⓘ
where O: AsRef<ExId>,

Iterate over the values in a map, list, or text object as at heads Read more
§

fn length<O>(&self, obj: O) -> usize
where O: AsRef<ExId>,

Get the length of the given object. Read more
§

fn length_at<O>(&self, obj: O, heads: &[ChangeHash]) -> usize
where O: AsRef<ExId>,

Get the length of the given object as at heads Read more
§

fn object_type<O>(&self, obj: O) -> Result<ObjType, AutomergeError>
where O: AsRef<ExId>,

Get the type of this object, if it is an object.
§

fn text<O>(&self, obj: O) -> Result<String, AutomergeError>
where O: AsRef<ExId>,

Get the string represented by the given text object.
§

fn text_at<O>( &self, obj: O, heads: &[ChangeHash], ) -> Result<String, AutomergeError>
where O: AsRef<ExId>,

Get the string represented by the given text object as at heads, see Self::text()
§

fn spans<O>(&self, obj: O) -> Result<Spans<'_>, AutomergeError>
where O: AsRef<ExId>,

Return the sequence of text and block markers in the text object obj
§

fn spans_at<O>( &self, obj: O, heads: &[ChangeHash], ) -> Result<Spans<'_>, AutomergeError>
where O: AsRef<ExId>,

Return the sequence of text and block markers in the text object obj as at heads
§

fn get_cursor<O, I>( &self, obj: O, position: I, at: Option<&[ChangeHash]>, ) -> Result<Cursor, AutomergeError>
where O: AsRef<ExId>, I: Into<CursorPosition>,

Obtain the stable address (Cursor) for a usize position in a Sequence (either ObjType::List or ObjType::Text). Read more
§

fn get_cursor_moving<O, I>( &self, obj: O, position: I, at: Option<&[ChangeHash]>, move_cursor: MoveCursor, ) -> Result<Cursor, AutomergeError>
where O: AsRef<ExId>, I: Into<CursorPosition>,

Obtain the stable address (Cursor) for a usize position in a Sequence (either ObjType::List or ObjType::Text). Read more
§

fn get_cursor_position<O>( &self, obj: O, address: &Cursor, at: Option<&[ChangeHash]>, ) -> Result<usize, AutomergeError>
where O: AsRef<ExId>,

Translate Cursor in a Sequence into an absolute position of type usize. Read more
§

fn marks<O>(&self, obj: O) -> Result<Vec<Mark>, AutomergeError>
where O: AsRef<ExId>,

Get all marks on a current sequence
§

fn marks_at<O>( &self, obj: O, heads: &[ChangeHash], ) -> Result<Vec<Mark>, AutomergeError>
where O: AsRef<ExId>,

Get all marks on a sequence at a given heads
§

fn hydrate<O>( &self, obj: O, heads: Option<&[ChangeHash]>, ) -> Result<Value, AutomergeError>
where O: AsRef<ExId>,

§

fn get_marks<O>( &self, obj: O, index: usize, heads: Option<&[ChangeHash]>, ) -> Result<MarkSet, AutomergeError>
where O: AsRef<ExId>,

§

fn get<O, P>( &self, obj: O, prop: P, ) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
where O: AsRef<ExId>, P: Into<Prop>,

Get a value out of the document. Read more
§

fn get_at<O, P>( &self, obj: O, prop: P, heads: &[ChangeHash], ) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
where O: AsRef<ExId>, P: Into<Prop>,

Get the value of the given key as at heads, see Self::get()
§

fn get_all<O, P>( &self, obj: O, prop: P, ) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
where O: AsRef<ExId>, P: Into<Prop>,

Get all conflicting values out of the document at this prop that conflict. Read more
§

fn get_all_at<O, P>( &self, obj: O, prop: P, heads: &[ChangeHash], ) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
where O: AsRef<ExId>, P: Into<Prop>,

Get all possibly conflicting values for a key as at heads Read more
§

fn parents<O>(&self, obj: O) -> Result<Parents<'_>, AutomergeError>
where O: AsRef<ExId>,

Get the parents of an object in the document tree. Read more
§

fn parents_at<O>( &self, obj: O, heads: &[ChangeHash], ) -> Result<Parents<'_>, AutomergeError>
where O: AsRef<ExId>,

Get the parents of the object obj as at heads Read more
§

fn get_missing_deps(&self, heads: &[ChangeHash]) -> Vec<ChangeHash>

Get the hashes of the changes in this document that aren’t transitive dependencies of the given heads.
§

fn get_change_by_hash(&self, hash: &ChangeHash) -> Option<Change>

Get a change by its hash.
§

fn stats(&self) -> Stats

Return some statistics about the document
§

fn text_encoding(&self) -> TextEncoding

§

fn iter(&self) -> DocIter<'_> ⓘ

Iterate over all the objects in the document Read more
§

impl Transactable for Transaction<'_>

§

fn pending_ops(&self) -> usize

Get the number of pending operations in this transaction.
§

fn put<O, P, V>( &mut self, obj: O, prop: P, value: V, ) -> Result<(), AutomergeError>
where O: AsRef<ExId>, P: Into<Prop>, V: Into<ScalarValue>,

Set the value of property P to value V in object obj. Read more
§

fn put_object<O, P>( &mut self, obj: O, prop: P, value: ObjType, ) -> Result<ExId, AutomergeError>
where O: AsRef<ExId>, P: Into<Prop>,

Set the value of property P to the new object V in object obj. Read more
§

fn insert<O, V>( &mut self, obj: O, index: usize, value: V, ) -> Result<(), AutomergeError>
where O: AsRef<ExId>, V: Into<ScalarValue>,

Insert a value into a list at the given index.
§

fn insert_object<O>( &mut self, obj: O, index: usize, value: ObjType, ) -> Result<ExId, AutomergeError>
where O: AsRef<ExId>,

Insert an object into a list at the given index.
§

fn increment<O, P>( &mut self, obj: O, prop: P, value: i64, ) -> Result<(), AutomergeError>
where O: AsRef<ExId>, P: Into<Prop>,

Increment the counter at the prop in the object by value.
§

fn delete<O, P>(&mut self, obj: O, prop: P) -> Result<(), AutomergeError>
where O: AsRef<ExId>, P: Into<Prop>,

Delete the value at prop in the object.
§

fn splice<O, V, I>( &mut self, obj: O, pos: usize, del: isize, vals: I, ) -> Result<(), AutomergeError>
where O: AsRef<ExId>, V: Into<Value>, I: IntoIterator<Item = V>,

replace a section of a list. If del is positive then N values are deleted after position pos and the new values inserted. If it is negative then N values are deleted before position pos instead. Read more
§

fn splice_text<O>( &mut self, obj: O, pos: usize, del: isize, text: &str, ) -> Result<(), AutomergeError>
where O: AsRef<ExId>,

Like Self::splice but for text.
§

fn mark<O>( &mut self, obj: O, mark: Mark, expand: ExpandMark, ) -> Result<(), AutomergeError>
where O: AsRef<ExId>,

Mark a sequence
§

fn unmark<O>( &mut self, obj: O, name: &str, start: usize, end: usize, expand: ExpandMark, ) -> Result<(), AutomergeError>
where O: AsRef<ExId>,

Remove a Mark from a sequence
§

fn split_block<O>( &mut self, obj: O, index: usize, ) -> Result<ExId, AutomergeError>
where O: AsRef<ExId>,

Insert a block marker into the text object obj at the given index. Read more
§

fn join_block<O>(&mut self, text: O, index: usize) -> Result<(), AutomergeError>
where O: AsRef<ExId>,

Delete a block marker at index from the text object obj.
§

fn replace_block<O>( &mut self, text: O, index: usize, ) -> Result<ExId, AutomergeError>
where O: AsRef<ExId>,

Replace a block marker at index in obj with a new marker and return the ID of the new marker
§

fn base_heads(&self) -> Vec<ChangeHash>

The heads this transaction will be based on
§

fn update_text<S>( &mut self, obj: &ExId, new_text: S, ) -> Result<(), AutomergeError>
where S: AsRef<str>,

Update the value of a string Read more
§

fn update_spans<O, I>( &mut self, text: O, config: UpdateSpansConfig, new_text: I, ) -> Result<(), AutomergeError>
where O: AsRef<ExId>, I: IntoIterator<Item = Span>,

Update the blocks and text in a text object Read more
§

fn update_object<O>( &mut self, obj: O, new_value: &Value, ) -> Result<(), UpdateObjectError>
where O: AsRef<ExId>,

§

fn batch_create_object<O, P>( &mut self, obj: O, prop: P, value: &Value, insert: bool, ) -> Result<ExId, AutomergeError>
where O: AsRef<ExId>, P: Into<Prop>,

Put or insert a nested hydrate::Value as a new object tree using batch operations. Read more
§

fn init_root_from_hydrate(&mut self, value: &Map) -> Result<(), AutomergeError>

Overwrite the keys of the root object with the values from value Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Transaction<'a>

§

impl<'a> RefUnwindSafe for Transaction<'a>

§

impl<'a> Send for Transaction<'a>

§

impl<'a> Sync for Transaction<'a>

§

impl<'a> Unpin for Transaction<'a>

§

impl<'a> UnsafeUnpin for Transaction<'a>

§

impl<'a> !UnwindSafe for Transaction<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> ReadTyped for T
where T: ReadDoc + ?Sized,

§

fn str_at(&self, obj: &ExId, prop: impl Into<Prop>) -> Option<String>

The string at prop of obj.
§

fn int_at(&self, obj: &ExId, prop: impl Into<Prop>) -> Option<i64>

The integer at prop of obj, when it fits an i64.
§

fn uint_at(&self, obj: &ExId, prop: impl Into<Prop>) -> Option<u64>

The integer at prop of obj, when it fits a u64.
§

fn f64_at(&self, obj: &ExId, prop: impl Into<Prop>) -> Option<f64>

The number at prop of obj as a float.
§

fn bool_at(&self, obj: &ExId, prop: impl Into<Prop>) -> Option<bool>

The boolean at prop of obj.
§

fn bytes_at(&self, obj: &ExId, prop: impl Into<Prop>) -> Option<Vec<u8>>

The bytes at prop of obj.
§

fn obj_at( &self, obj: &ExId, prop: impl Into<Prop>, kind: ObjType, ) -> Option<ExId>

The object of type kind at prop of obj.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> WriteTyped for T
where T: Transactable + ?Sized,

§

fn put_str_if_changed( &mut self, obj: &ExId, prop: impl Into<Prop>, value: &str, ) -> Result<(), AutomergeError>

Put the string value at prop of obj unless it is already there. Read more
§

fn put_uint_if_changed( &mut self, obj: &ExId, prop: impl Into<Prop>, value: u64, ) -> Result<(), AutomergeError>

Put the unsigned integer value at prop of obj unless it is already there. Read more
§

fn put_opt_str_if_changed( &mut self, obj: &ExId, prop: impl Into<Prop>, value: Option<&str>, ) -> Result<(), AutomergeError>

Put value at prop of obj when it is Some and differs; delete the entry when it is None and a value is present. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Fruit for T
where T: Send + Downcast,

§

impl<T> MaybeSendSync for T
where T: Send + Sync + ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T

§

impl<T> WasmNotSync for T
where T: Sync,