pub struct CollectionDocument<C> where
C: SerializedCollection, {
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
sourceimpl<C> CollectionDocument<C> where
C: SerializedCollection,
impl<C> CollectionDocument<C> where
C: SerializedCollection,
sourcepub async fn update<Cn>(&'_ mut self, connection: &'_ Cn) -> Result<(), Error> where
Cn: Connection,
pub async fn update<Cn>(&'_ mut self, connection: &'_ Cn) -> Result<(), Error> where
Cn: Connection,
Stores the new value of contents
in the document.
if let Some(mut document) = MyCollection::get(42, &db).await? {
// modify the document
document.update(&db).await?;
println!("Updated revision: {:?}", document.header.revision);
}
sourcepub async fn modify<Cn, Modifier>(
&'_ mut self,
connection: &'_ Cn,
modifier: Modifier
) -> Result<(), Error> where
Cn: Connection,
Modifier: FnMut(&mut CollectionDocument<C>) + Send + Sync,
<C as SerializedCollection>::Contents: Clone,
pub async fn modify<Cn, Modifier>(
&'_ mut self,
connection: &'_ Cn,
modifier: Modifier
) -> Result<(), Error> where
Cn: Connection,
Modifier: FnMut(&mut CollectionDocument<C>) + Send + Sync,
<C as SerializedCollection>::Contents: Clone,
Modifies self
, automatically retrying the modification if the document
has been updated on the server.
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.
sourcepub async fn delete<Cn>(&'_ self, connection: &'_ Cn) -> Result<(), Error> where
Cn: Connection,
pub async 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).await? {
document.delete(&db).await?;
}
sourcepub fn to_document(&self) -> Result<OwnedDocument, Error>
pub fn to_document(&self) -> Result<OwnedDocument, Error>
Converts this value to a serialized Document
.
Trait Implementations
sourceimpl<C> Clone for CollectionDocument<C> where
C: Clone + SerializedCollection,
<C as Collection>::PrimaryKey: Clone,
<C as SerializedCollection>::Contents: Clone,
impl<C> Clone for CollectionDocument<C> where
C: Clone + SerializedCollection,
<C as Collection>::PrimaryKey: Clone,
<C as SerializedCollection>::Contents: Clone,
sourcefn clone(&self) -> CollectionDocument<C>
fn clone(&self) -> CollectionDocument<C>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<C> Debug for CollectionDocument<C> where
C: Debug + SerializedCollection,
<C as Collection>::PrimaryKey: Debug,
<C as SerializedCollection>::Contents: Debug,
impl<C> Debug for CollectionDocument<C> where
C: Debug + SerializedCollection,
<C as Collection>::PrimaryKey: Debug,
<C as SerializedCollection>::Contents: Debug,
sourceimpl<C> HasHeader for CollectionDocument<C> where
C: SerializedCollection,
impl<C> HasHeader for CollectionDocument<C> where
C: SerializedCollection,
sourceimpl<'a, C> Nameable<'a, <C as Collection>::PrimaryKey> for &'a CollectionDocument<C> where
C: SerializedCollection,
impl<'a, C> Nameable<'a, <C as Collection>::PrimaryKey> for &'a CollectionDocument<C> where
C: SerializedCollection,
sourcefn name(
self
) -> Result<NamedReference<'a, <C as Collection>::PrimaryKey>, Error>
fn name(
self
) -> Result<NamedReference<'a, <C as Collection>::PrimaryKey>, Error>
Returns this name as a NamedReference
.
sourceimpl<C> PartialEq<CollectionDocument<C>> for CollectionDocument<C> where
C: PartialEq<C> + SerializedCollection,
<C as Collection>::PrimaryKey: PartialEq<<C as Collection>::PrimaryKey>,
<C as SerializedCollection>::Contents: PartialEq<<C as SerializedCollection>::Contents>,
impl<C> PartialEq<CollectionDocument<C>> for CollectionDocument<C> where
C: PartialEq<C> + SerializedCollection,
<C as Collection>::PrimaryKey: PartialEq<<C as Collection>::PrimaryKey>,
<C as SerializedCollection>::Contents: PartialEq<<C as SerializedCollection>::Contents>,
sourcefn eq(&self, other: &CollectionDocument<C>) -> bool
fn eq(&self, other: &CollectionDocument<C>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &CollectionDocument<C>) -> bool
fn ne(&self, other: &CollectionDocument<C>) -> bool
This method tests for !=
.
sourceimpl<'a, C> TryFrom<&'a BorrowedDocument<'a>> for CollectionDocument<C> where
C: SerializedCollection,
impl<'a, C> TryFrom<&'a BorrowedDocument<'a>> for CollectionDocument<C> where
C: SerializedCollection,
sourcefn try_from(
value: &'a BorrowedDocument<'a>
) -> Result<CollectionDocument<C>, <CollectionDocument<C> as TryFrom<&'a BorrowedDocument<'a>>>::Error>
fn try_from(
value: &'a BorrowedDocument<'a>
) -> Result<CollectionDocument<C>, <CollectionDocument<C> as TryFrom<&'a BorrowedDocument<'a>>>::Error>
Performs the conversion.
sourceimpl<'a, C> TryFrom<&'a OwnedDocument> for CollectionDocument<C> where
C: SerializedCollection,
impl<'a, C> TryFrom<&'a OwnedDocument> for CollectionDocument<C> where
C: SerializedCollection,
sourcefn try_from(
value: &'a OwnedDocument
) -> Result<CollectionDocument<C>, <CollectionDocument<C> as TryFrom<&'a OwnedDocument>>::Error>
fn try_from(
value: &'a OwnedDocument
) -> Result<CollectionDocument<C>, <CollectionDocument<C> as TryFrom<&'a OwnedDocument>>::Error>
Performs the conversion.
sourceimpl<'a, 'b, C> TryFrom<&'b CollectionDocument<C>> for BorrowedDocument<'a> where
C: SerializedCollection,
impl<'a, 'b, C> TryFrom<&'b CollectionDocument<C>> for BorrowedDocument<'a> where
C: SerializedCollection,
sourcefn try_from(
value: &'b CollectionDocument<C>
) -> Result<BorrowedDocument<'a>, <BorrowedDocument<'a> as TryFrom<&'b CollectionDocument<C>>>::Error>
fn try_from(
value: &'b CollectionDocument<C>
) -> Result<BorrowedDocument<'a>, <BorrowedDocument<'a> as TryFrom<&'b CollectionDocument<C>>>::Error>
Performs the conversion.
sourceimpl<'a, 'c, C> TryFrom<&'c CollectionDocument<C>> for NamedReference<'a, <C as Collection>::PrimaryKey> where
C: SerializedCollection,
impl<'a, 'c, C> TryFrom<&'c CollectionDocument<C>> for NamedReference<'a, <C as Collection>::PrimaryKey> where
C: SerializedCollection,
sourcefn try_from(
doc: &'c CollectionDocument<C>
) -> Result<NamedReference<'a, <C as Collection>::PrimaryKey>, Error>
fn try_from(
doc: &'c CollectionDocument<C>
) -> Result<NamedReference<'a, <C as Collection>::PrimaryKey>, Error>
Performs the conversion.
impl<C> Eq for CollectionDocument<C> where
C: Eq + SerializedCollection,
<C as Collection>::PrimaryKey: Eq,
<C as SerializedCollection>::Contents: Eq,
impl<C> StructuralEq for CollectionDocument<C> where
C: SerializedCollection,
impl<C> StructuralPartialEq for CollectionDocument<C> where
C: SerializedCollection,
Auto Trait Implementations
impl<C> RefUnwindSafe for CollectionDocument<C> where
<C as SerializedCollection>::Contents: RefUnwindSafe,
<C as Collection>::PrimaryKey: RefUnwindSafe,
impl<C> Send for CollectionDocument<C>
impl<C> Sync for CollectionDocument<C>
impl<C> Unpin for CollectionDocument<C> where
<C as SerializedCollection>::Contents: Unpin,
<C as Collection>::PrimaryKey: Unpin,
impl<C> UnwindSafe for CollectionDocument<C> where
<C as SerializedCollection>::Contents: UnwindSafe,
<C as Collection>::PrimaryKey: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more