pub trait Document<C>: Sizedwhere
    C: Collection,{
    type Bytes;

    // Required methods
    fn id(&self) -> &DocumentId;
    fn header(&self) -> AnyHeader<<C as Collection>::PrimaryKey>;
    fn set_header(&mut self, header: Header) -> Result<(), Error>;
    fn bytes(&self) -> Result<Vec<u8, Global>, Error>;
    fn contents(&self) -> Result<<C as SerializedCollection>::Contents, Error>
       where C: SerializedCollection;
    fn set_contents(
        &mut self,
        contents: <C as SerializedCollection>::Contents
    ) -> Result<(), Error>
       where C: SerializedCollection;

    // Provided method
    fn set_collection_header(
        &mut self,
        header: CollectionHeader<<C as Collection>::PrimaryKey>
    ) -> Result<(), Error> { ... }
}
Expand description

Common interface of a document in BonsaiDb.

Required Associated Types§

type Bytes

The bytes type used in the interface.

Required Methods§

fn id(&self) -> &DocumentId

Returns the unique key for this document.

fn header(&self) -> AnyHeader<<C as Collection>::PrimaryKey>

Returns the header of this document.

fn set_header(&mut self, header: Header) -> Result<(), Error>

Sets the header to the new header.

fn bytes(&self) -> Result<Vec<u8, Global>, Error>

Returns the contents of this document, serialized.

fn contents(&self) -> Result<<C as SerializedCollection>::Contents, Error>where C: SerializedCollection,

Retrieves contents through deserialization into the type D.

fn set_contents( &mut self, contents: <C as SerializedCollection>::Contents ) -> Result<(), Error>where C: SerializedCollection,

Stores contents into this document.

Provided Methods§

fn set_collection_header( &mut self, header: CollectionHeader<<C as Collection>::PrimaryKey> ) -> Result<(), Error>

Sets the header to the new collection header.

Implementors§

§

impl<'a, C> Document<C> for BorrowedDocument<'a>where C: Collection,

§

type Bytes = CowBytes<'a>

§

impl<C> Document<C> for OwnedDocumentwhere C: Collection,

§

type Bytes = Vec<u8, Global>