Struct bonsaidb_core::document::CollectionDocument
source · [−]pub struct CollectionDocument<C> where
C: SerializedCollection, {
pub header: Header,
pub contents: C::Contents,
}Expand description
A document with serializable contents.
Fields
header: HeaderThe 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>
pub async fn modify<Cn: Connection, Modifier: FnMut(&mut Self) + Send + Sync>(
&mut self,
connection: &Cn,
modifier: Modifier
) -> Result<(), Error>
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.
Methods from Deref<Target = Header>
sourcepub fn emit_key<K: for<'a> Key<'a>>(&self, key: K) -> Mappings<K, ()>
pub fn emit_key<K: for<'a> Key<'a>>(&self, key: K) -> Mappings<K, ()>
Creates a Map result with a key and an empty value.
sourcepub fn emit_value<Value>(&self, value: Value) -> Mappings<(), Value>
pub fn emit_value<Value>(&self, value: Value) -> Mappings<(), Value>
Creates a Map result with value and an empty key.
sourcepub fn emit_key_and_value<K: for<'a> Key<'a>, Value>(
&self,
key: K,
value: Value
) -> Mappings<K, Value>
pub fn emit_key_and_value<K: for<'a> Key<'a>, Value>(
&self,
key: K,
value: Value
) -> Mappings<K, Value>
Creates a Map result with a key and value.
Trait Implementations
sourceimpl<C> AsRef<Header> for CollectionDocument<C> where
C: SerializedCollection,
impl<C> AsRef<Header> for CollectionDocument<C> where
C: SerializedCollection,
sourceimpl<C: Clone> Clone for CollectionDocument<C> where
C: SerializedCollection,
C::Contents: Clone,
impl<C: Clone> Clone for CollectionDocument<C> where
C: SerializedCollection,
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::Contents: Debug,
impl<C: Debug> Debug for CollectionDocument<C> where
C: SerializedCollection,
C::Contents: Debug,
sourceimpl<C> Deref for CollectionDocument<C> where
C: SerializedCollection,
impl<C> Deref for CollectionDocument<C> where
C: SerializedCollection,
sourceimpl<'a, 'c, C> From<&'c CollectionDocument<C>> for NamedReference<'a> where
C: SerializedCollection,
impl<'a, 'c, C> From<&'c CollectionDocument<C>> for NamedReference<'a> where
C: SerializedCollection,
sourcefn from(doc: &'c CollectionDocument<C>) -> Self
fn from(doc: &'c CollectionDocument<C>) -> Self
Performs the conversion.
sourceimpl<C: PartialEq> PartialEq<CollectionDocument<C>> for CollectionDocument<C> where
C: SerializedCollection,
C::Contents: PartialEq,
impl<C: PartialEq> PartialEq<CollectionDocument<C>> for CollectionDocument<C> where
C: SerializedCollection,
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,
impl<C: Eq> Eq for CollectionDocument<C> where
C: SerializedCollection,
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,
impl<C> Send for CollectionDocument<C>
impl<C> Sync for CollectionDocument<C>
impl<C> Unpin for CollectionDocument<C> where
<C as SerializedCollection>::Contents: Unpin,
impl<C> UnwindSafe for CollectionDocument<C> where
<C as SerializedCollection>::Contents: 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