Struct pliantdb_core::document::Document[][src]

pub struct Document<'a> {
    pub collection: Id,
    pub header: Cow<'a, Header>,
    pub contents: Cow<'a, [u8]>,
}

Contains a serialized document in the database.

Fields

collection: Id

The Id of the Collection this document belongs to.

header: Cow<'a, Header>

The header of the document, which contains the id and Revision.

contents: Cow<'a, [u8]>

The serialized bytes of the stored item.

Implementations

impl<'a> Document<'a>[src]

#[must_use]pub fn new(id: u64, contents: Cow<'a, [u8]>, collection: Id) -> Self[src]

Creates a new document with contents.

pub fn with_contents<S: Serialize>(
    id: u64,
    contents: &S,
    collection: Id
) -> Result<Self, Error>
[src]

Creates a new document with serialized bytes from contents.

pub fn contents<D: Deserialize<'a>>(&'a self) -> Result<D, Error>[src]

Retrieves contents through deserialization into the type D.

pub fn set_contents<S: Serialize>(&mut self, contents: &S) -> Result<(), Error>[src]

Serializes and stores contents into this document.

#[must_use]pub fn create_new_revision(&self, contents: Cow<'a, [u8]>) -> Option<Self>[src]

Creates a new revision.

WARNING: This normally should not be used outside of implementing a backend for PliantDB. To update a document, use set_contents() and send the document with the existing Revision information.

#[must_use]pub fn emit(&self) -> Map<(), ()>[src]

Creates a Map result with an empty key and value.

#[must_use]pub fn emit_key<Key: Key>(&self, key: Key) -> Map<Key, ()>[src]

Creates a Map result with a key and an empty value.

#[must_use]pub fn emit_value<Value: Serialize>(&self, value: Value) -> Map<(), Value>[src]

Creates a Map result with value and an empty key.

#[must_use]pub fn emit_key_and_value<Key: Key, Value: Serialize>(
    &self,
    key: Key,
    value: Value
) -> Map<Key, Value>
[src]

Creates a Map result with a key and value.

#[must_use]pub fn to_owned(&self) -> Document<'static>[src]

Clone the document’s data so that it’s no longer borrowed in the original lifetime 'a.

Trait Implementations

impl<'a> Clone for Document<'a>[src]

impl<'a> Debug for Document<'a>[src]

impl<'de, 'a> Deserialize<'de> for Document<'a>[src]

impl<'a> Serialize for Document<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Document<'a>

impl<'a> Send for Document<'a>

impl<'a> Sync for Document<'a>

impl<'a> Unpin for Document<'a>

impl<'a> UnwindSafe for Document<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.