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§
Source§impl<'a> Transaction<'a>
impl<'a> Transaction<'a>
Sourcepub 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
Source§impl<'a> Transaction<'a>
impl<'a> Transaction<'a>
Sourcepub fn get_heads(&self) -> Vec<ChangeHash>
pub fn get_heads(&self) -> Vec<ChangeHash>
Get the heads of the document before this transaction was started.
Sourcepub 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.
Sourcepub 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§
Source§impl<'a> Debug for Transaction<'a>
impl<'a> Debug for Transaction<'a>
Source§impl<'a> Drop for Transaction<'a>
impl<'a> Drop for Transaction<'a>
Source§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()
.
Source§impl<'a> ReadDoc for Transaction<'a>
impl<'a> ReadDoc for Transaction<'a>
Source§fn keys<O: AsRef<ExId>>(&self, obj: O) -> Keys<'_> ⓘ
fn keys<O: AsRef<ExId>>(&self, obj: O) -> Keys<'_> ⓘ
obj
. Read moreSource§fn map_range<'b, O: AsRef<ExId>, R: RangeBounds<String> + 'b>(
&'b self,
obj: O,
range: R,
) -> MapRange<'b, R> ⓘ
fn map_range<'b, O: AsRef<ExId>, R: RangeBounds<String> + 'b>( &'b self, obj: O, range: R, ) -> MapRange<'b, R> ⓘ
obj
in the given range. Read moreSource§fn map_range_at<'b, O: AsRef<ExId>, R: RangeBounds<String> + 'b>(
&'b self,
obj: O,
range: R,
heads: &[ChangeHash],
) -> MapRange<'b, R> ⓘ
fn map_range_at<'b, O: AsRef<ExId>, R: RangeBounds<String> + 'b>( &'b self, obj: O, range: R, heads: &[ChangeHash], ) -> MapRange<'b, R> ⓘ
Source§fn list_range<O: AsRef<ExId>, R: RangeBounds<usize>>(
&self,
obj: O,
range: R,
) -> ListRange<'_, R> ⓘ
fn list_range<O: AsRef<ExId>, R: RangeBounds<usize>>( &self, obj: O, range: R, ) -> ListRange<'_, R> ⓘ
obj
in the given range. Read moreSource§fn list_range_at<O: AsRef<ExId>, R: RangeBounds<usize>>(
&self,
obj: O,
range: R,
heads: &[ChangeHash],
) -> ListRange<'_, R> ⓘ
fn list_range_at<O: AsRef<ExId>, R: RangeBounds<usize>>( &self, obj: O, range: R, heads: &[ChangeHash], ) -> ListRange<'_, R> ⓘ
obj
in the given range as at heads
Read moreSource§fn values<O: AsRef<ExId>>(&self, obj: O) -> Values<'_> ⓘ
fn values<O: AsRef<ExId>>(&self, obj: O) -> Values<'_> ⓘ
Source§fn values_at<O: AsRef<ExId>>(&self, obj: O, heads: &[ChangeHash]) -> Values<'_> ⓘ
fn values_at<O: AsRef<ExId>>(&self, obj: O, heads: &[ChangeHash]) -> Values<'_> ⓘ
heads
Read moreSource§fn length<O: AsRef<ExId>>(&self, obj: O) -> usize
fn length<O: AsRef<ExId>>(&self, obj: O) -> usize
Source§fn length_at<O: AsRef<ExId>>(&self, obj: O, heads: &[ChangeHash]) -> usize
fn length_at<O: AsRef<ExId>>(&self, obj: O, heads: &[ChangeHash]) -> usize
heads
Read moreSource§fn object_type<O: AsRef<ExId>>(&self, obj: O) -> Result<ObjType, AutomergeError>
fn object_type<O: AsRef<ExId>>(&self, obj: O) -> Result<ObjType, AutomergeError>
Source§fn text<O: AsRef<ExId>>(&self, obj: O) -> Result<String, AutomergeError>
fn text<O: AsRef<ExId>>(&self, obj: O) -> Result<String, AutomergeError>
Source§fn text_at<O: AsRef<ExId>>(
&self,
obj: O,
heads: &[ChangeHash],
) -> Result<String, AutomergeError>
fn text_at<O: AsRef<ExId>>( &self, obj: O, heads: &[ChangeHash], ) -> Result<String, AutomergeError>
heads
, see
Self::text()
Source§fn spans<O: AsRef<ExId>>(&self, obj: O) -> Result<Spans<'_>, AutomergeError>
fn spans<O: AsRef<ExId>>(&self, obj: O) -> Result<Spans<'_>, AutomergeError>
obj
Source§fn spans_at<O: AsRef<ExId>>(
&self,
obj: O,
heads: &[ChangeHash],
) -> Result<Spans<'_>, AutomergeError>
fn spans_at<O: AsRef<ExId>>( &self, obj: O, heads: &[ChangeHash], ) -> Result<Spans<'_>, AutomergeError>
obj
as at heads
Source§fn get_cursor<O: AsRef<ExId>, I: Into<CursorPosition>>(
&self,
obj: O,
position: I,
at: Option<&[ChangeHash]>,
) -> Result<Cursor, AutomergeError>
fn get_cursor<O: AsRef<ExId>, I: Into<CursorPosition>>( &self, obj: O, position: I, at: Option<&[ChangeHash]>, ) -> Result<Cursor, AutomergeError>
usize
position in a Sequence (either ObjType::List
or ObjType::Text
). Read moreSource§fn get_cursor_moving<O: AsRef<ExId>, I: Into<CursorPosition>>(
&self,
obj: O,
position: I,
at: Option<&[ChangeHash]>,
move_cursor: MoveCursor,
) -> Result<Cursor, AutomergeError>
fn get_cursor_moving<O: AsRef<ExId>, I: Into<CursorPosition>>( &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 moreSource§fn get_cursor_position<O: AsRef<ExId>>(
&self,
obj: O,
address: &Cursor,
at: Option<&[ChangeHash]>,
) -> Result<usize, AutomergeError>
fn get_cursor_position<O: AsRef<ExId>>( &self, obj: O, address: &Cursor, at: Option<&[ChangeHash]>, ) -> Result<usize, AutomergeError>
Source§fn marks<O: AsRef<ExId>>(&self, obj: O) -> Result<Vec<Mark<'_>>, AutomergeError>
fn marks<O: AsRef<ExId>>(&self, obj: O) -> Result<Vec<Mark<'_>>, AutomergeError>
Source§fn marks_at<O: AsRef<ExId>>(
&self,
obj: O,
heads: &[ChangeHash],
) -> Result<Vec<Mark<'_>>, AutomergeError>
fn marks_at<O: AsRef<ExId>>( &self, obj: O, heads: &[ChangeHash], ) -> Result<Vec<Mark<'_>>, AutomergeError>
fn hydrate<O: AsRef<ExId>>( &self, obj: O, heads: Option<&[ChangeHash]>, ) -> Result<Value, AutomergeError>
fn get_marks<O: AsRef<ExId>>( &self, obj: O, index: usize, heads: Option<&[ChangeHash]>, ) -> Result<MarkSet, AutomergeError>
Source§fn get<O: AsRef<ExId>, P: Into<Prop>>(
&self,
obj: O,
prop: P,
) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
fn get<O: AsRef<ExId>, P: Into<Prop>>( &self, obj: O, prop: P, ) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
Source§fn get_at<O: AsRef<ExId>, P: Into<Prop>>(
&self,
obj: O,
prop: P,
heads: &[ChangeHash],
) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
fn get_at<O: AsRef<ExId>, P: Into<Prop>>( &self, obj: O, prop: P, heads: &[ChangeHash], ) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
heads
, see Self::get()
Source§fn get_all<O: AsRef<ExId>, P: Into<Prop>>(
&self,
obj: O,
prop: P,
) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
fn get_all<O: AsRef<ExId>, P: Into<Prop>>( &self, obj: O, prop: P, ) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
Source§fn get_all_at<O: AsRef<ExId>, P: Into<Prop>>(
&self,
obj: O,
prop: P,
heads: &[ChangeHash],
) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
fn get_all_at<O: AsRef<ExId>, P: Into<Prop>>( &self, obj: O, prop: P, heads: &[ChangeHash], ) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
heads
Read moreSource§fn parents<O: AsRef<ExId>>(&self, obj: O) -> Result<Parents<'_>, AutomergeError>
fn parents<O: AsRef<ExId>>(&self, obj: O) -> Result<Parents<'_>, AutomergeError>
Source§fn parents_at<O: AsRef<ExId>>(
&self,
obj: O,
heads: &[ChangeHash],
) -> Result<Parents<'_>, AutomergeError>
fn parents_at<O: AsRef<ExId>>( &self, obj: O, heads: &[ChangeHash], ) -> Result<Parents<'_>, AutomergeError>
Source§fn get_missing_deps(&self, heads: &[ChangeHash]) -> Vec<ChangeHash>
fn get_missing_deps(&self, heads: &[ChangeHash]) -> Vec<ChangeHash>
heads
.Source§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
Source§impl<'a> Transactable for Transaction<'a>
impl<'a> Transactable for Transaction<'a>
Source§fn pending_ops(&self) -> usize
fn pending_ops(&self) -> usize
Get the number of pending operations in this transaction.
Source§fn put<O: AsRef<ExId>, P: Into<Prop>, V: Into<ScalarValue>>(
&mut self,
obj: O,
prop: P,
value: V,
) -> Result<(), AutomergeError>
fn put<O: AsRef<ExId>, P: Into<Prop>, V: Into<ScalarValue>>( &mut self, obj: O, prop: P, value: V, ) -> Result<(), AutomergeError>
Set the value of property P
to value V
in object obj
.
§Errors
This will return an error if
- The object does not exist
- The key is the wrong type for the object
- The key does not exist in the object
Source§fn splice<O: AsRef<ExId>, V: IntoIterator<Item = ScalarValue>>(
&mut self,
obj: O,
pos: usize,
del: isize,
vals: V,
) -> Result<(), AutomergeError>
fn splice<O: AsRef<ExId>, V: IntoIterator<Item = ScalarValue>>( &mut self, obj: O, pos: usize, del: isize, vals: V, ) -> Result<(), AutomergeError>
Splice new elements into the given sequence. Returns a vector of the OpIds used to insert the new elements
Source§fn put_object<O: AsRef<ExId>, P: Into<Prop>>(
&mut self,
obj: O,
prop: P,
value: ObjType,
) -> Result<ExId, AutomergeError>
fn put_object<O: AsRef<ExId>, P: Into<Prop>>( &mut self, obj: O, prop: P, value: ObjType, ) -> Result<ExId, AutomergeError>
Source§fn insert<O: AsRef<ExId>, V: Into<ScalarValue>>(
&mut self,
obj: O,
index: usize,
value: V,
) -> Result<(), AutomergeError>
fn insert<O: AsRef<ExId>, V: Into<ScalarValue>>( &mut self, obj: O, index: usize, value: V, ) -> Result<(), AutomergeError>
Source§fn insert_object<O: AsRef<ExId>>(
&mut self,
obj: O,
index: usize,
value: ObjType,
) -> Result<ExId, AutomergeError>
fn insert_object<O: AsRef<ExId>>( &mut self, obj: O, index: usize, value: ObjType, ) -> Result<ExId, AutomergeError>
Source§fn increment<O: AsRef<ExId>, P: Into<Prop>>(
&mut self,
obj: O,
prop: P,
value: i64,
) -> Result<(), AutomergeError>
fn increment<O: AsRef<ExId>, P: Into<Prop>>( &mut self, obj: O, prop: P, value: i64, ) -> Result<(), AutomergeError>
value
.Source§fn delete<O: AsRef<ExId>, P: Into<Prop>>(
&mut self,
obj: O,
prop: P,
) -> Result<(), AutomergeError>
fn delete<O: AsRef<ExId>, P: Into<Prop>>( &mut self, obj: O, prop: P, ) -> Result<(), AutomergeError>
Source§fn splice_text<O: AsRef<ExId>>(
&mut self,
obj: O,
pos: usize,
del: isize,
text: &str,
) -> Result<(), AutomergeError>
fn splice_text<O: AsRef<ExId>>( &mut self, obj: O, pos: usize, del: isize, text: &str, ) -> Result<(), AutomergeError>
Self::splice
but for text.Source§fn mark<O: AsRef<ExId>>(
&mut self,
obj: O,
mark: Mark<'_>,
expand: ExpandMark,
) -> Result<(), AutomergeError>
fn mark<O: AsRef<ExId>>( &mut self, obj: O, mark: Mark<'_>, expand: ExpandMark, ) -> Result<(), AutomergeError>
Source§fn unmark<O: AsRef<ExId>>(
&mut self,
obj: O,
name: &str,
start: usize,
end: usize,
expand: ExpandMark,
) -> Result<(), AutomergeError>
fn unmark<O: AsRef<ExId>>( &mut self, obj: O, name: &str, start: usize, end: usize, expand: ExpandMark, ) -> Result<(), AutomergeError>
Source§fn split_block<'p, O>(
&mut self,
obj: O,
index: usize,
) -> Result<ExId, AutomergeError>
fn split_block<'p, O>( &mut self, obj: O, index: usize, ) -> Result<ExId, AutomergeError>
obj
at the given index. Read moreSource§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
.Source§fn replace_block<'p, O>(
&mut self,
text: O,
index: usize,
) -> Result<ExId, AutomergeError>
fn replace_block<'p, O>( &mut self, text: O, index: usize, ) -> Result<ExId, AutomergeError>
index
in obj
with a new marker and return the ID of the new
markerSource§fn base_heads(&self) -> Vec<ChangeHash>
fn base_heads(&self) -> Vec<ChangeHash>
Source§fn update_text<S: AsRef<str>>(
&mut self,
obj: &ExId,
new_text: S,
) -> Result<(), AutomergeError>
fn update_text<S: AsRef<str>>( &mut self, obj: &ExId, new_text: S, ) -> Result<(), AutomergeError>
Source§fn update_spans<'b, O: AsRef<ExId>, I: IntoIterator<Item = BlockOrText<'b>>>(
&mut self,
text: O,
new_text: I,
) -> Result<(), AutomergeError>
fn update_spans<'b, O: AsRef<ExId>, I: IntoIterator<Item = BlockOrText<'b>>>( &mut self, text: O, new_text: I, ) -> Result<(), AutomergeError>
fn update_object<O: AsRef<ExId>>( &mut self, obj: O, new_value: &Value, ) -> Result<(), UpdateObjectError>
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> !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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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