pub struct CollectionDocument<C>{
    pub header: CollectionHeader<<C as Collection>::PrimaryKey>,
    pub contents: <C as SerializedCollection>::Contents,
}
Expand description

A document with serializable contents.

Fields§

§header: CollectionHeader<<C as Collection>::PrimaryKey>

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

§contents: <C as SerializedCollection>::Contents

The document’s contents.

Implementations§

source§

impl<C> CollectionDocument<C>

source

pub fn update<Cn>(&mut self, connection: &Cn) -> Result<(), Error>
where Cn: Connection,

Updates the document stored in the database with the contents of this collection document.

if let Some(mut document) = MyCollection::get(&42, &db)? {
    // ... do something `document`
    document.update(&db)?;
    println!(
        "The document has been updated: {:?}",
        document.header.revision
    );
}
source

pub fn update_in_transaction( &self, transaction: &mut Transaction ) -> Result<(), Error>

Pushes an update Operation to the transaction for this document.

The changes will happen once the transaction is applied.

source

pub async fn update_async<Cn>(&mut self, connection: &Cn) -> Result<(), Error>
where Cn: AsyncConnection,

Stores the new value of contents in the document.

if let Some(mut document) = MyCollection::get_async(&42, &db).await? {
    // modify the document
    document.update_async(&db).await?;
    println!("Updated revision: {:?}", document.header.revision);
}
source

pub fn modify<R, Cn, Modifier>( &mut self, connection: &Cn, modifier: Modifier ) -> Result<R, Error>
where Cn: Connection, Modifier: FnMut(&mut CollectionDocument<C>) -> R + Send + Sync, <C as SerializedCollection>::Contents: Clone,

Modifies self, automatically retrying the modification if the document has been updated on the server.

The contents of Ok will be the last value returned from modifier.

Data loss warning

If you’ve modified self before calling this function and a conflict occurs, all changes to self will be lost when the current document is fetched before retrying the process again. When you use this function, you should limit the edits to the value to within the modifier callback.

source

pub async fn modify_async<R, Cn, Modifier>( &mut self, connection: &Cn, modifier: Modifier ) -> Result<R, Error>
where Cn: AsyncConnection, Modifier: FnMut(&mut CollectionDocument<C>) -> R + Send + Sync, <C as SerializedCollection>::Contents: Clone,

Modifies self, automatically retrying the modification if the document has been updated on the server.

The contents of Ok will be the last value returned from modifier.

Data loss warning

If you’ve modified self before calling this function and a conflict occurs, all changes to self will be lost when the current document is fetched before retrying the process again. When you use this function, you should limit the edits to the value to within the modifier callback.

source

pub fn delete<Cn>(&self, connection: &Cn) -> Result<(), Error>
where Cn: Connection,

Removes the document from the collection.

if let Some(document) = MyCollection::get(&42, &db)? {
    document.delete(&db)?;
}
source

pub async fn delete_async<Cn>(&self, connection: &Cn) -> Result<(), Error>
where Cn: AsyncConnection,

Removes the document from the collection.

if let Some(document) = MyCollection::get_async(&42, &db).await? {
    document.delete_async(&db).await?;
}
source

pub fn delete_in_transaction( &self, transaction: &mut Transaction ) -> Result<(), Error>

Pushes a delete Operation to the transaction for this document.

The document will be deleted once the transaction is applied.

source

pub fn refresh<Cn>(&mut self, connection: &Cn) -> Result<(), Error>
where Cn: Connection,

Refreshes this instance from connection. If the document is no longer present, Error::DocumentNotFound will be returned.

source

pub async fn refresh_async<Cn>(&mut self, connection: &Cn) -> Result<(), Error>
where Cn: AsyncConnection,

Refreshes this instance from connection. If the document is no longer present, Error::DocumentNotFound will be returned.

source

pub fn to_document(&self) -> Result<OwnedDocument, Error>

Converts this value to a serialized Document.

Trait Implementations§

source§

impl<C> Clone for CollectionDocument<C>

source§

fn clone(&self) -> CollectionDocument<C>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<C> Debug for CollectionDocument<C>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'de, C> Deserialize<'de> for CollectionDocument<C>

source§

fn deserialize<D>( deserializer: D ) -> Result<CollectionDocument<C>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<C> HasHeader for CollectionDocument<C>

source§

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

Returns the header for this instance.
source§

impl<'a, C> Nameable<'a, <C as Collection>::PrimaryKey> for &'a CollectionDocument<C>

source§

fn name( self ) -> Result<NamedReference<'a, <C as Collection>::PrimaryKey>, Error>

Returns this name as a NamedReference.
source§

impl<C> PartialEq for CollectionDocument<C>

source§

fn eq(&self, other: &CollectionDocument<C>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<C> Serialize for CollectionDocument<C>

source§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'a, C> TryFrom<&'a BorrowedDocument<'a>> for CollectionDocument<C>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a BorrowedDocument<'a> ) -> Result<CollectionDocument<C>, <CollectionDocument<C> as TryFrom<&'a BorrowedDocument<'a>>>::Error>

Performs the conversion.
source§

impl<'a, 'b, C> TryFrom<&'b CollectionDocument<C>> for BorrowedDocument<'a>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from( value: &'b CollectionDocument<C> ) -> Result<BorrowedDocument<'a>, <BorrowedDocument<'a> as TryFrom<&'b CollectionDocument<C>>>::Error>

Performs the conversion.
source§

impl<'a, 'c, C> TryFrom<&'c CollectionDocument<C>> for NamedReference<'a, <C as Collection>::PrimaryKey>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from( doc: &'c CollectionDocument<C> ) -> Result<NamedReference<'a, <C as Collection>::PrimaryKey>, Error>

Performs the conversion.
source§

impl<'a, C> TryFrom<&'a OwnedDocument> for CollectionDocument<C>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a OwnedDocument ) -> Result<CollectionDocument<C>, <CollectionDocument<C> as TryFrom<&'a OwnedDocument>>::Error>

Performs the conversion.
source§

impl<C> Eq for CollectionDocument<C>

source§

impl<C> StructuralEq for CollectionDocument<C>

source§

impl<C> StructuralPartialEq for CollectionDocument<C>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

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