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>
impl<'a> Transaction<'a>
pub fn hash_for_opid(&self, opid: &ExId) -> Option<ChangeHash>
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<'_>
impl Transaction<'_>
pub fn get_heads(&self) -> Vec<ChangeHash>
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)
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)
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));Trait Implementations§
§impl<'a> Debug for Transaction<'a>
impl<'a> Debug for Transaction<'a>
§impl Drop for Transaction<'_>
impl Drop for Transaction<'_>
§fn drop(&mut self)
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().
§impl ReadDoc for Transaction<'_>
impl ReadDoc for Transaction<'_>
§fn keys_at<O>(&self, obj: O, heads: &[ChangeHash]) -> Keys<'_> ⓘ
fn keys_at<O>(&self, obj: O, heads: &[ChangeHash]) -> Keys<'_> ⓘ
§fn map_range<'b, O, R>(&'b self, obj: O, range: R) -> MapRange<'b> ⓘ
fn map_range<'b, O, R>(&'b self, obj: O, range: R) -> MapRange<'b> ⓘ
obj in the given range. Read more§fn map_range_at<'b, O, R>(
&'b self,
obj: O,
range: R,
heads: &[ChangeHash],
) -> MapRange<'b> ⓘ
fn map_range_at<'b, O, R>( &'b self, obj: O, range: R, heads: &[ChangeHash], ) -> MapRange<'b> ⓘ
§fn list_range<O, R>(&self, obj: O, range: R) -> ListRange<'_> ⓘ
fn list_range<O, R>(&self, obj: O, range: R) -> ListRange<'_> ⓘ
obj in the given range. Read more§fn list_range_at<O, R>(
&self,
obj: O,
range: R,
heads: &[ChangeHash],
) -> ListRange<'_> ⓘ
fn list_range_at<O, R>( &self, obj: O, range: R, heads: &[ChangeHash], ) -> ListRange<'_> ⓘ
obj in the given range as at heads Read more§fn values<O>(&self, obj: O) -> Values<'_> ⓘ
fn values<O>(&self, obj: O) -> Values<'_> ⓘ
§fn values_at<O>(&self, obj: O, heads: &[ChangeHash]) -> Values<'_> ⓘ
fn values_at<O>(&self, obj: O, heads: &[ChangeHash]) -> Values<'_> ⓘ
heads Read more§fn length_at<O>(&self, obj: O, heads: &[ChangeHash]) -> usize
fn length_at<O>(&self, obj: O, heads: &[ChangeHash]) -> usize
heads Read more§fn object_type<O>(&self, obj: O) -> Result<ObjType, AutomergeError>
fn object_type<O>(&self, obj: O) -> Result<ObjType, AutomergeError>
§fn text<O>(&self, obj: O) -> Result<String, AutomergeError>
fn text<O>(&self, obj: O) -> Result<String, AutomergeError>
§fn text_at<O>(
&self,
obj: O,
heads: &[ChangeHash],
) -> Result<String, AutomergeError>
fn text_at<O>( &self, obj: O, heads: &[ChangeHash], ) -> Result<String, AutomergeError>
heads, see
Self::text()§fn spans<O>(&self, obj: O) -> Result<Spans<'_>, AutomergeError>
fn spans<O>(&self, obj: O) -> Result<Spans<'_>, AutomergeError>
obj§fn spans_at<O>(
&self,
obj: O,
heads: &[ChangeHash],
) -> Result<Spans<'_>, AutomergeError>
fn spans_at<O>( &self, obj: O, heads: &[ChangeHash], ) -> Result<Spans<'_>, AutomergeError>
obj as at heads§fn get_cursor<O, I>(
&self,
obj: O,
position: I,
at: Option<&[ChangeHash]>,
) -> Result<Cursor, AutomergeError>
fn get_cursor<O, I>( &self, obj: O, position: I, at: Option<&[ChangeHash]>, ) -> Result<Cursor, AutomergeError>
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>
fn get_cursor_moving<O, I>( &self, obj: O, position: I, at: Option<&[ChangeHash]>, move_cursor: MoveCursor, ) -> Result<Cursor, AutomergeError>
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>
fn get_cursor_position<O>( &self, obj: O, address: &Cursor, at: Option<&[ChangeHash]>, ) -> Result<usize, AutomergeError>
§fn marks_at<O>(
&self,
obj: O,
heads: &[ChangeHash],
) -> Result<Vec<Mark>, AutomergeError>
fn marks_at<O>( &self, obj: O, heads: &[ChangeHash], ) -> Result<Vec<Mark>, AutomergeError>
fn hydrate<O>( &self, obj: O, heads: Option<&[ChangeHash]>, ) -> Result<Value, AutomergeError>
fn get_marks<O>( &self, obj: O, index: usize, heads: Option<&[ChangeHash]>, ) -> Result<MarkSet, AutomergeError>
§fn get<O, P>(
&self,
obj: O,
prop: P,
) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
fn get<O, P>( &self, obj: O, prop: P, ) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
§fn get_at<O, P>(
&self,
obj: O,
prop: P,
heads: &[ChangeHash],
) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
fn get_at<O, P>( &self, obj: O, prop: P, heads: &[ChangeHash], ) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
heads, see Self::get()§fn get_all<O, P>(
&self,
obj: O,
prop: P,
) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
fn get_all<O, P>( &self, obj: O, prop: P, ) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
§fn get_all_at<O, P>(
&self,
obj: O,
prop: P,
heads: &[ChangeHash],
) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
fn get_all_at<O, P>( &self, obj: O, prop: P, heads: &[ChangeHash], ) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
heads Read more§fn parents<O>(&self, obj: O) -> Result<Parents<'_>, AutomergeError>
fn parents<O>(&self, obj: O) -> Result<Parents<'_>, AutomergeError>
§fn parents_at<O>(
&self,
obj: O,
heads: &[ChangeHash],
) -> Result<Parents<'_>, AutomergeError>
fn parents_at<O>( &self, obj: O, heads: &[ChangeHash], ) -> Result<Parents<'_>, AutomergeError>
§fn get_missing_deps(&self, heads: &[ChangeHash]) -> Vec<ChangeHash>
fn get_missing_deps(&self, heads: &[ChangeHash]) -> Vec<ChangeHash>
heads.§fn get_change_by_hash(&self, hash: &ChangeHash) -> Option<Change>
fn get_change_by_hash(&self, hash: &ChangeHash) -> Option<Change>
fn text_encoding(&self) -> TextEncoding
§impl Transactable for Transaction<'_>
impl Transactable for Transaction<'_>
§fn pending_ops(&self) -> usize
fn pending_ops(&self) -> usize
§fn put<O, P, V>(
&mut self,
obj: O,
prop: P,
value: V,
) -> Result<(), AutomergeError>
fn put<O, P, V>( &mut self, obj: O, prop: P, value: V, ) -> Result<(), AutomergeError>
§fn put_object<O, P>(
&mut self,
obj: O,
prop: P,
value: ObjType,
) -> Result<ExId, AutomergeError>
fn put_object<O, P>( &mut self, obj: O, prop: P, value: ObjType, ) -> Result<ExId, AutomergeError>
§fn insert<O, V>(
&mut self,
obj: O,
index: usize,
value: V,
) -> Result<(), AutomergeError>
fn insert<O, V>( &mut self, obj: O, index: usize, value: V, ) -> Result<(), AutomergeError>
§fn insert_object<O>(
&mut self,
obj: O,
index: usize,
value: ObjType,
) -> Result<ExId, AutomergeError>
fn insert_object<O>( &mut self, obj: O, index: usize, value: ObjType, ) -> Result<ExId, AutomergeError>
§fn increment<O, P>(
&mut self,
obj: O,
prop: P,
value: i64,
) -> Result<(), AutomergeError>
fn increment<O, P>( &mut self, obj: O, prop: P, value: i64, ) -> Result<(), AutomergeError>
value.§fn delete<O, P>(&mut self, obj: O, prop: P) -> Result<(), AutomergeError>
fn delete<O, P>(&mut self, obj: O, prop: P) -> Result<(), AutomergeError>
§fn splice<O, V, I>(
&mut self,
obj: O,
pos: usize,
del: isize,
vals: I,
) -> Result<(), AutomergeError>
fn splice<O, V, I>( &mut self, obj: O, pos: usize, del: isize, vals: I, ) -> Result<(), AutomergeError>
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>
fn splice_text<O>( &mut self, obj: O, pos: usize, del: isize, text: &str, ) -> Result<(), AutomergeError>
Self::splice but for text.§fn mark<O>(
&mut self,
obj: O,
mark: Mark,
expand: ExpandMark,
) -> Result<(), AutomergeError>
fn mark<O>( &mut self, obj: O, mark: Mark, expand: ExpandMark, ) -> Result<(), AutomergeError>
§fn unmark<O>(
&mut self,
obj: O,
name: &str,
start: usize,
end: usize,
expand: ExpandMark,
) -> Result<(), AutomergeError>
fn unmark<O>( &mut self, obj: O, name: &str, start: usize, end: usize, expand: ExpandMark, ) -> Result<(), AutomergeError>
§fn split_block<O>(
&mut self,
obj: O,
index: usize,
) -> Result<ExId, AutomergeError>
fn split_block<O>( &mut self, obj: O, index: usize, ) -> Result<ExId, AutomergeError>
obj at the given index. Read more§fn join_block<O>(&mut self, text: O, index: usize) -> Result<(), AutomergeError>
fn join_block<O>(&mut self, text: O, index: usize) -> Result<(), AutomergeError>
index from the text object obj.§fn replace_block<O>(
&mut self,
text: O,
index: usize,
) -> Result<ExId, AutomergeError>
fn replace_block<O>( &mut self, text: O, index: usize, ) -> Result<ExId, AutomergeError>
index in obj with a new marker and return the ID of the new
marker§fn base_heads(&self) -> Vec<ChangeHash>
fn base_heads(&self) -> Vec<ChangeHash>
§fn update_text<S>(
&mut self,
obj: &ExId,
new_text: S,
) -> Result<(), AutomergeError>
fn update_text<S>( &mut self, obj: &ExId, new_text: S, ) -> Result<(), AutomergeError>
§fn update_spans<O, I>(
&mut self,
text: O,
config: UpdateSpansConfig,
new_text: I,
) -> Result<(), AutomergeError>
fn update_spans<O, I>( &mut self, text: O, config: UpdateSpansConfig, new_text: I, ) -> Result<(), AutomergeError>
fn update_object<O>( &mut self, obj: O, new_value: &Value, ) -> Result<(), UpdateObjectError>
§fn batch_create_object<O, P>(
&mut self,
obj: O,
prop: P,
value: &Value,
insert: bool,
) -> Result<ExId, AutomergeError>
fn batch_create_object<O, P>( &mut self, obj: O, prop: P, value: &Value, insert: bool, ) -> Result<ExId, AutomergeError>
hydrate::Value as a new object tree using
batch operations. Read more§fn init_root_from_hydrate(&mut self, value: &Map) -> Result<(), AutomergeError>
fn init_root_from_hydrate(&mut self, value: &Map) -> Result<(), AutomergeError>
value Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> Pointable for T
§impl<T> ReadTyped for T
impl<T> ReadTyped for T
§fn int_at(&self, obj: &ExId, prop: impl Into<Prop>) -> Option<i64>
fn int_at(&self, obj: &ExId, prop: impl Into<Prop>) -> Option<i64>
prop of obj, when it fits an i64.§fn uint_at(&self, obj: &ExId, prop: impl Into<Prop>) -> Option<u64>
fn uint_at(&self, obj: &ExId, prop: impl Into<Prop>) -> Option<u64>
prop of obj, when it fits a u64.