pub struct Document { /* private fields */ }Expand description
High-level datatype representing data published to the p2panda network as key-value pairs.
Documents are multi-writer and have automatic conflict resolution strategies which produce deterministic
state for any two replicas. The underlying structure which make this possible is a directed acyclic graph
of Operation’s. To arrive at the current state of a document the graph is topologically sorted,
with any branches being ordered according to the conflicting operations OperationId. Each operation’s
mutation is applied in order which results in a LWW (last write wins) resolution strategy.
All documents have an accompanying Schema which describes the shape of the data they will contain. Every
operation should have been validated against this schema before being included in the graph.
Documents are constructed through the DocumentBuilder or by conversion from vectors of a type implementing
the AsOperation, WithId<OperationId> and WithPublicKey.
To efficiently commit more operations to an already constructed document use the commit
method. Any operations committed in this way must refer to the documents current view id in
their previous field.
See module docs for example uses.
Trait Implementations§
Source§impl AsDocument for Document
impl AsDocument for Document
Source§fn id(&self) -> &DocumentId
fn id(&self) -> &DocumentId
Get the document id.
Source§fn view_id(&self) -> &DocumentViewId
fn view_id(&self) -> &DocumentViewId
Get the document view id.
Get the document author’s public key.
Source§fn fields(&self) -> Option<&DocumentViewFields>
fn fields(&self) -> Option<&DocumentViewFields>
Get the fields of this document.
Source§fn update_view(
&mut self,
id: &DocumentViewId,
view: Option<&DocumentViewFields>,
)
fn update_view( &mut self, id: &DocumentViewId, view: Option<&DocumentViewFields>, )
Update the current view of this document.
Source§fn is_deleted(&self) -> bool
fn is_deleted(&self) -> bool
Source§fn view(&self) -> Option<DocumentView>
fn view(&self) -> Option<DocumentView>
Source§fn get(&self, key: &str) -> Option<&OperationValue>
fn get(&self, key: &str) -> Option<&OperationValue>
Source§fn commit<T: AsOperation>(
&mut self,
operation_id: &OperationId,
operation: &T,
) -> Result<(), DocumentError>
fn commit<T: AsOperation>( &mut self, operation_id: &OperationId, operation: &T, ) -> Result<(), DocumentError>
Source§fn commit_unchecked<T: AsOperation>(
&mut self,
operation_id: &OperationId,
operation: &T,
)
fn commit_unchecked<T: AsOperation>( &mut self, operation_id: &OperationId, operation: &T, )
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more