Struct ditto::json::Json
[−]
[src]
pub struct Json { /* fields omitted */ }
Json is a CRDT that stores a JSON value. It can handle any kind of JSON value (object, array, string, number, bool, and null) and allows arbitrarily-nested values. A nested Json value is indexed by a JSON pointer.
Internally, Json is built on Ditto's Map
,
List
, and Text
CRDTs. It allows op-based replication via execute_op
and state-based replication via merge
.
State-based replication allows out-of-order delivery but
op-based replication does not.
The root value of a Json CRDT (typically an object or array) cannot be replaced; for example, a Json CRDT whose root is an array will always have an array as its root. This constraint means that any Json CRDT with a numeric, boolean, or null root is immutable.
Methods
impl Json
[src]
pub fn new<T: IntoJson>(local_value: T) -> Result<Self, Error>
[src]
Constructs and returns a new Json
CRDT with site 1 from any
value that satisfies the IntoJson
trait.
pub fn from_str(json_str: &str) -> Result<Self, Error>
[src]
Constructs and returns a new Json
CRDT with site 1 from an
unparsed JSON string.
pub fn len(&self, pointer: &str) -> Option<usize>
[src]
Returns the number of elements in a container at the given
pointer in the Json
CRDT. If there is no container at the
given pointer, returns None
.
pub fn insert<T: IntoJson>(
&mut self,
pointer: &str,
value: T
) -> Result<Op, Error>
[src]
&mut self,
pointer: &str,
value: T
) -> Result<Op, Error>
Inserts a value into the Json CRDT at the given json pointer.
The enclosing value may be an object or an array and the
inserted value must satisfy the IntoJson
trait.
If the CRDT does not have a site id allocated, it caches
the op and returns an AwaitingSite
error.
pub fn insert_str(&mut self, pointer: &str, value: &str) -> Result<Op, Error>
[src]
Inserts a value into the Json CRDT at the given json pointer. The enclosing value may be an object or an array and the value being inserted is stringified JSON.
If the CRDT does not have a site id allocated, it caches
the op and returns an AwaitingSite
error.
pub fn remove(&mut self, pointer: &str) -> Result<Op, Error>
[src]
Removes a value at the given JSON pointer from the Json CRDT. If the enclosing value is an object, it deletes the key-value pair. If the enclosing value is an array, it deletes the value at the array index.
If the CRDT does not have a site id allocated, it caches
the op and returns an AwaitingSite
error.
pub fn replace_text(
&mut self,
pointer: &str,
index: usize,
len: usize,
text: &str
) -> Result<Op, Error>
[src]
&mut self,
pointer: &str,
index: usize,
len: usize,
text: &str
) -> Result<Op, Error>
Replaces a text range in a text value in the Json CRDT.
If the CRDT does not have a site id allocated, it caches
the op and returns an AwaitingSite
error.
pub fn site_id(&self) -> SiteId
[src]
Returns the site id.
pub fn state(&self) -> JsonState
[src]
Returns a borrowed CRDT state.
pub fn clone_state(&self) -> JsonState<'static>
[src]
Returns an owned CRDT state of cloned values.
pub fn into_state(self) -> JsonState<'static>
[src]
Consumes the CRDT and returns its state
pub fn from_state(
state: JsonState,
site_id: Option<SiteId>
) -> Result<Self, Error>
[src]
state: JsonState,
site_id: Option<SiteId>
) -> Result<Self, Error>
Constructs a new CRDT from a state and optional site id. If the site id is present, it must be nonzero.
pub fn local_value(&self) -> SJValue
[src]
Returns the CRDT value's equivalent local value.
pub fn execute_op(&mut self, op: Op) -> Option<LocalOp>
[src]
Executes an op and returns the equivalent local op.
This function assumes that the op always inserts values
from the correct site. For untrusted ops, used validate_and_execute_op
.
pub fn validate_and_execute_op(
&mut self,
op: Op,
site_id: SiteId
) -> Result<Option<LocalOp>, Error>
[src]
&mut self,
op: Op,
site_id: SiteId
) -> Result<Option<LocalOp>, Error>
Validates that an op only inserts elements from a given site id, then executes the op and returns the equivalent local op.
pub fn merge(&mut self, other: JsonState) -> Result<(), Error>
[src]
Merges a remote CRDT state into the CRDT. The remote CRDT state must have a site id.
pub fn add_site_id(&mut self, site_id: SiteId) -> Result<Vec<Op>, Error>
[src]
Assigns a site id to the CRDT and returns any cached ops. If the CRDT already has a site id, it returns an error.
Trait Implementations
impl Debug for Json
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Clone for Json
[src]
fn clone(&self) -> Json
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more