Trait bonsaidb_core::document::Document
source · [−]pub trait Document<'a>: Deref<Target = Header> + DerefMut + AsRef<Header> + AsRef<[u8]> + Sized {
type Bytes;
fn new(id: u64, contents: impl Into<Self::Bytes>) -> Self;
fn with_contents<S: SerializedCollection<Contents = S>>(
id: u64,
contents: &S
) -> Result<Self, Error>;
fn contents<D>(&self) -> Result<D::Contents, Error>
where
D: SerializedCollection<Contents = D>;
fn set_contents<S: SerializedCollection<Contents = S>>(
&mut self,
contents: &S
) -> Result<(), Error>;
fn create_new_revision(
&self,
contents: impl Into<Self::Bytes>
) -> Option<Self>;
}Expand description
Common interface of a document in BonsaiDb.
Associated Types
Required methods
Creates a new document with contents.
fn with_contents<S: SerializedCollection<Contents = S>>(
id: u64,
contents: &S
) -> Result<Self, Error>
fn with_contents<S: SerializedCollection<Contents = S>>(
id: u64,
contents: &S
) -> Result<Self, Error>
Creates a new document with serialized bytes from contents.
Retrieves contents through deserialization into the type D.
fn set_contents<S: SerializedCollection<Contents = S>>(
&mut self,
contents: &S
) -> Result<(), Error>
fn set_contents<S: SerializedCollection<Contents = S>>(
&mut self,
contents: &S
) -> Result<(), Error>
Serializes and stores contents into this document.
fn create_new_revision(&self, contents: impl Into<Self::Bytes>) -> Option<Self>
fn create_new_revision(&self, contents: impl Into<Self::Bytes>) -> Option<Self>
Creates a new revision.
WARNING: This normally should not be used outside of implementing a
backend for BonsaiDb. To update a document, use set_contents() and
send the document with the existing Revision information.