Struct bonsaidb_core::document::CollectionDocument
source · [−]pub struct CollectionDocument<C> where
C: SerializedCollection, {
pub header: CollectionHeader<C::PrimaryKey>,
pub contents: C::Contents,
}Expand description
A document with serializable contents.
Fields
header: CollectionHeader<C::PrimaryKey>The header of the document, which contains the id and Revision.
contents: C::ContentsThe document’s contents.
Implementations
sourceimpl<C> CollectionDocument<C> where
C: SerializedCollection,
impl<C> CollectionDocument<C> where
C: SerializedCollection,
sourcepub async fn update<Cn: Connection>(
&mut self,
connection: &Cn
) -> Result<(), Error>
pub async fn update<Cn: Connection>(
&mut self,
connection: &Cn
) -> Result<(), Error>
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: Connection, Modifier: FnMut(&mut Self) + Send + Sync>(
&mut self,
connection: &Cn,
modifier: Modifier
) -> Result<(), Error> where
C::Contents: Clone,
pub async fn modify<Cn: Connection, Modifier: FnMut(&mut Self) + Send + Sync>(
&mut self,
connection: &Cn,
modifier: Modifier
) -> Result<(), Error> where
C::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: Connection>(&self, connection: &Cn) -> Result<(), Error>
pub async fn delete<Cn: Connection>(&self, connection: &Cn) -> Result<(), Error>
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> Clone for CollectionDocument<C> where
C: SerializedCollection,
C::PrimaryKey: Clone,
C::Contents: Clone,
impl<C: Clone> Clone for CollectionDocument<C> where
C: SerializedCollection,
C::PrimaryKey: Clone,
C::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> Debug for CollectionDocument<C> where
C: SerializedCollection,
C::PrimaryKey: Debug,
C::Contents: Debug,
impl<C: Debug> Debug for CollectionDocument<C> where
C: SerializedCollection,
C::PrimaryKey: Debug,
C::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::PrimaryKey>, Error>
fn name(self) -> Result<NamedReference<'a, C::PrimaryKey>, Error>
Returns this name as a NamedReference.
sourceimpl<C: PartialEq> PartialEq<CollectionDocument<C>> for CollectionDocument<C> where
C: SerializedCollection,
C::PrimaryKey: PartialEq,
C::Contents: PartialEq,
impl<C: PartialEq> PartialEq<CollectionDocument<C>> for CollectionDocument<C> where
C: SerializedCollection,
C::PrimaryKey: PartialEq,
C::Contents: PartialEq,
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,
sourceimpl<'a, C> TryFrom<&'a OwnedDocument> for CollectionDocument<C> where
C: SerializedCollection,
impl<'a, C> TryFrom<&'a OwnedDocument> for CollectionDocument<C> where
C: SerializedCollection,
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,
sourceimpl<'a, 'c, C> TryFrom<&'c CollectionDocument<C>> for NamedReference<'a, C::PrimaryKey> where
C: SerializedCollection,
impl<'a, 'c, C> TryFrom<&'c CollectionDocument<C>> for NamedReference<'a, C::PrimaryKey> where
C: SerializedCollection,
impl<C: Eq> Eq for CollectionDocument<C> where
C: SerializedCollection,
C::PrimaryKey: Eq,
C::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 · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
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.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more