Trait dittolive_ditto::store::collection::document::DittoDocument
source · [−]pub trait DittoDocument {
fn id(&self) -> DocumentId;
fn to_cbor(&self) -> Result<Value, DittoError>;
fn get<V: DeserializeOwned>(&self, path: &str) -> Result<V, DittoError>;
fn typed<T: DeserializeOwned>(&self) -> Result<T, DittoError>;
}
Expand description
DittoDocument
s can be obtained via calls to the various
exec
methods
or via the various
observe_local
methods, exposed via the objects
returned from calls to Collection::find_by_id
,
Collection::find
, and
Collection::find_all
.
This is the readonly view of the document as it is currently stored in the
Collection
and it will not be updated if the document is
changed.
Required Methods
sourcefn id(&self) -> DocumentId
fn id(&self) -> DocumentId
Returns the DocumentId
of the document.
sourcefn to_cbor(&self) -> Result<Value, DittoError>
fn to_cbor(&self) -> Result<Value, DittoError>
Renders the document as a CBOR value.
sourcefn get<V: DeserializeOwned>(&self, path: &str) -> Result<V, DittoError>
fn get<V: DeserializeOwned>(&self, path: &str) -> Result<V, DittoError>
Returns the value at a given path in the document.
The parameter V
represents the type expected at the given path. Note, however, that other
peers may have changed this type and deserialization may fail. In this case provide a
general type like serde_cbor::Value
.
sourcefn typed<T: DeserializeOwned>(&self) -> Result<T, DittoError>
fn typed<T: DeserializeOwned>(&self) -> Result<T, DittoError>
Decodes a document into a user-provided type provided that type implements
serde::Deserialize
.
Note that this is a snapshot of the current state of the document, which may be later modified by other peers