pub struct AutoCommitWithObs<Obs: Observation> { /* private fields */ }
Expand description

An automerge document that automatically manages transactions.

An AutoCommit can optionally manage an OpObserver. This observer will be notified of all changes made by both remote and local changes. The type parameter O tracks whether this document is observed or not.

Creating, loading, merging and forking documents

A new document can be created with Self::new, which will create a document with a random ActorId. Existing documents can be loaded with Self::load.

If you have two documents and you want to merge the changes from one into the other you can use Self::merge.

If you have a document you want to split into two concurrent threads of execution you can use Self::fork. If you want to split a document from ealier in its history you can use Self::fork_at.

Reading values

Self implements ReadDoc, which provides methods for reading values from the document.

Modifying a document

This type implements Transactable directly, so you can modify it using methods from Transactable.

Synchronization

To synchronise call Self::sync which returns an implementation of SyncDoc

Observers

An AutoCommit can optionally manage an OpObserver. Self::new will return a document with no observer but you can set an observer using Self::with_observer. The observer must implement both OpObserver and BranchableObserver. If you have an observed autocommit then you can obtain a mutable reference to the observer with Self::observer

Implementations§

Change the text encoding of this view of the document

This is a cheap operation, it just changes the way indexes are calculated

Load an incremental save of a document.

Unlike load this imports changes into an existing document. It will work with both the output of Self::save and Self::save_incremental

The return value is the number of ops which were applied, this is not useful and will change in future.

Takes all the changes in other which are not in self and applies them

Save the entirety of this document in a compact form.

Save this document, but don’t run it through DEFLATE afterwards

Save the changes since the last call to Self::save`

The output of this will not be a compressed document format, but a series of individual changes. This is useful if you know you have only made a small change since the last save and you want to immediately send it somewhere (e.g. you’ve inserted a single character in a text object).

Get the last change made by this documents actor ID

Get changes in other that are not in `self

Return a graphviz representation of the opset.

Arguments
  • objects: An optional list of object IDs to display, if not specified all objects are visualised

Get the current heads of the document.

This closes the transaction first, if one is in progress.

Commit any uncommitted changes

Returns None if there were no operations to commit

Commit the current operations with some options.

Returns None if there were no operations to commit

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

Remove any changes that have been made in the current transaction from the document

Generate an empty change

The main reason to do this is if you wish to create a “merge commit” which has all the current heads of the documents as dependencies but you have no new operations to create.

Because this structure is an “autocommit” there may actually be outstanding operations to submit. If this is the case this function will create two changes, one with the outstanding operations and a new one with no operations. The returned ChangeHash will always be the hash of the empty change.

An implementation of crate::sync::SyncDoc for this autocommit

This ensures that any outstanding transactions for this document are committed before taking part in the sync protocol

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Get the parents of an object in the document tree. Read more
Get the path to an object Read more
Get the keys of the object obj. Read more
Get the keys of the object obj as at heads Read more
Iterate over the keys and values of the map obj in the given range. Read more
Iterate over the keys and values of the map obj in the given range as at heads Read more
Iterate over the indexes and values of the list or text obj in the given range. Read more
Iterate over the indexes and values of the list or text obj in the given range as at heads Read more
Iterate over the values in a map, list, or text object Read more
Iterate over the values in a map, list, or text object as at heads Read more
Get the length of the given object. Read more
Get the length of the given object as at heads Read more
Get the type of this object, if it is an object.
Get the string represented by the given text object.
Get the string represented by the given text object as at heads, see Self::text Read more
Get a value out of the document. Read more
Get the value of the given key as at heads, see [Self::get]
Get all conflicting values out of the document at this prop that conflict. Read more
Get all possibly conflicting values for a key as at heads Read more
Get the hashes of the changes in this document that aren’t transitive dependencies of the given heads. Read more
Get a change by its hash.

Splice new elements into the given sequence. Returns a vector of the OpIds used to insert the new elements

Get the number of pending operations in this transaction.
Set the value of property P to value V in object obj. Read more
Set the value of property P to the new object V in object obj. Read more
Insert a value into a list at the given index.
Insert an object into a list at the given index.
Increment the counter at the prop in the object by value.
Delete the value at prop in the object.
Like Self::splice but for text.
The heads this transaction will be based on

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

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

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more