Trait Transactable
pub trait Transactable: ReadDoc {
Show 20 methods
// Required methods
fn pending_ops(&self) -> usize;
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>;
fn put_object<O, P>(
&mut self,
obj: O,
prop: P,
object: ObjType,
) -> Result<ExId, AutomergeError>
where O: AsRef<ExId>,
P: Into<Prop>;
fn insert<O, V>(
&mut self,
obj: O,
index: usize,
value: V,
) -> Result<(), AutomergeError>
where O: AsRef<ExId>,
V: Into<ScalarValue>;
fn insert_object<O>(
&mut self,
obj: O,
index: usize,
object: ObjType,
) -> Result<ExId, AutomergeError>
where O: AsRef<ExId>;
fn increment<O, P>(
&mut self,
obj: O,
prop: P,
value: i64,
) -> Result<(), AutomergeError>
where O: AsRef<ExId>,
P: Into<Prop>;
fn delete<O, P>(&mut self, obj: O, prop: P) -> Result<(), AutomergeError>
where O: AsRef<ExId>,
P: Into<Prop>;
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>;
fn splice_text<O>(
&mut self,
obj: O,
pos: usize,
del: isize,
text: &str,
) -> Result<(), AutomergeError>
where O: AsRef<ExId>;
fn mark<O>(
&mut self,
obj: O,
mark: Mark,
expand: ExpandMark,
) -> Result<(), AutomergeError>
where O: AsRef<ExId>;
fn unmark<O>(
&mut self,
obj: O,
key: &str,
start: usize,
end: usize,
expand: ExpandMark,
) -> Result<(), AutomergeError>
where O: AsRef<ExId>;
fn split_block<O>(
&mut self,
obj: O,
index: usize,
) -> Result<ExId, AutomergeError>
where O: AsRef<ExId>;
fn join_block<O>(
&mut self,
text: O,
index: usize,
) -> Result<(), AutomergeError>
where O: AsRef<ExId>;
fn replace_block<O>(
&mut self,
text: O,
index: usize,
) -> Result<ExId, AutomergeError>
where O: AsRef<ExId>;
fn update_spans<O, I>(
&mut self,
text: O,
config: UpdateSpansConfig,
new_text: I,
) -> Result<(), AutomergeError>
where O: AsRef<ExId>,
I: IntoIterator<Item = Span>;
fn base_heads(&self) -> Vec<ChangeHash>;
fn update_text<S>(
&mut self,
obj: &ExId,
new_text: S,
) -> Result<(), AutomergeError>
where S: AsRef<str>;
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>;
fn init_root_from_hydrate(
&mut self,
value: &Map,
) -> Result<(), AutomergeError>;
}Expand description
A way of mutating a document within a single change.
Required Methods§
fn pending_ops(&self) -> usize
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>
fn put<O, P, V>( &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
fn put_object<O, P>(
&mut self,
obj: O,
prop: P,
object: ObjType,
) -> Result<ExId, AutomergeError>
fn put_object<O, P>( &mut self, obj: O, prop: P, object: 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>
Insert a value into a list at the given index.
fn insert_object<O>(
&mut self,
obj: O,
index: usize,
object: ObjType,
) -> Result<ExId, AutomergeError>
fn insert_object<O>( &mut self, obj: O, index: usize, object: ObjType, ) -> Result<ExId, AutomergeError>
Insert an object into a list at the given index.
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>
Increment the counter at the prop in the object by 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>
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>
fn splice<O, V, I>( &mut self, obj: O, pos: usize, del: isize, vals: I, ) -> Result<(), AutomergeError>
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.
Values can be scalars or nested objects (maps, lists, text). Scalar values are inserted directly, while nested objects are created using batch insertion for efficiency.
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>
Like 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>
Mark a sequence
fn unmark<O>(
&mut self,
obj: O,
key: &str,
start: usize,
end: usize,
expand: ExpandMark,
) -> Result<(), AutomergeError>
fn unmark<O>( &mut self, obj: O, key: &str, start: usize, end: usize, expand: ExpandMark, ) -> Result<(), AutomergeError>
Remove a Mark from a sequence
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>
Insert a block marker into the text object obj at the given index.
§Returns
The ID of the new block marker. The block marker is a plain old map so you can use all the normal methods of modifying a map to interact with it.
fn join_block<O>(&mut self, text: O, index: usize) -> Result<(), AutomergeError>
fn join_block<O>(&mut self, text: O, index: usize) -> Result<(), AutomergeError>
Delete a block marker at 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>
Replace a block marker at index in obj with a new marker and return the ID of the new
marker
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>
Update the blocks and text in a text object
This performs a diff against the current state of both the text and the block markers in a text object and attempts to perform a reasonably minimal set of operations to update the document to match the new text.
The config argument is an UpdateSpansConfig object which is used to configure how the
ExpandMark flag will be set for spans which are created as part of the reconciliation
fn base_heads(&self) -> Vec<ChangeHash>
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>
fn update_text<S>( &mut self, obj: &ExId, new_text: S, ) -> Result<(), AutomergeError>
Update the value of a string
This will calculate a diff between the current value and the new value and then convert that diff into calls to {@link splice}. This will produce results which don’t merge as well as directly capturing the user input actions, but sometimes it’s not possible to capture user input and this is the best you can do.
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>
Put or insert a nested hydrate::Value as a new object tree using
batch operations.
This is much faster than decomposing the value into individual put/insert operations because it only requires two OpSet splices instead of one per node.
When insert is true and prop is a sequence index, the value is
inserted at that index. When false, it overwrites the existing element.
For map keys, insert is ignored.
fn init_root_from_hydrate(&mut self, value: &Map) -> Result<(), AutomergeError>
fn init_root_from_hydrate(&mut self, value: &Map) -> Result<(), AutomergeError>
Overwrite the keys of the root object with the values from value
This is useful to initialize an empty document with a large initial
value. Note that existing keys which are not in value are left as is
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.