Struct automerge::Automerge

source ·
pub struct Automerge { /* private fields */ }
Expand description

An automerge document which does not manage transactions for you.

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, or Self::load_with.

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

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 (Transactions)

Automerge provides an interface for viewing and modifying automerge documents which does not manage transactions for you. To create changes you use either Automerge::transaction or Automerge::transact (or the _with variants).

Sync

This type implements crate::sync::SyncDoc

Observers

Many of the methods on this type have an _with or _observed variant which allow you to pass in an OpObserver to observe any changes which occur.

Implementations§

Create a new document with a random actor id.

Whether this document has any operations

Change the text encoding of this view of the document

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

Set the actor id for this document.

Set the actor id for this document.

Get the current actor id of this document.

Start a transaction.

Start a transaction with an observer

Run a transaction on this document in a closure, automatically handling commit or rollback afterwards.

Like Self::transact but with a function for generating the commit options.

Run a transaction on this document in a closure, observing ops with Obs, automatically handling commit or rollback afterwards.

Like Self::transact_observed but with a function for generating the commit options

Generate an empty change

The main reason to do this is if you want to create a “merge commit”, which is a change that has all the current heads of the document as dependencies.

Fork this document at the current point for use by a different actor.

This will create a new actor ID for the forked document

Fork this document at the given heads

This will create a new actor ID for the forked document

Load a document.

Load a document without verifying the head hashes

This is useful for debugging as it allows you to examine a corrupted document.

Load a document with an observer

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.

Like Self::load_incremental but with an observer

Apply changes to this document.

This is idemptotent in the sense that if a change has already been applied it will be ignored.

Like Self::apply_changes but with an observer

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

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

Save the entirety of this document in a compact form.

This takes a mutable reference to self because it saves the heads of the last save so that save_incremental can be used to produce only the changes since the last save. This API will be changing in future.

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 this actor made to the document.

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 heads of this document.

Get changes in other that are not in `self

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.
Generate a sync message for the remote peer represented by sync_state Read more
Apply a received sync message to this document and sync_state
Apply a received sync message to this document and sync_state, observing any changes with op_observer Read more

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