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§
Source§impl<C> CollectionDocument<C>where
C: SerializedCollection,
impl<C> CollectionDocument<C>where
C: SerializedCollection,
Sourcepub fn update<Cn: Connection>(&mut self, connection: &Cn) -> Result<(), Error>
pub fn update<Cn: Connection>(&mut self, connection: &Cn) -> Result<(), Error>
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
);
}Sourcepub fn update_in_transaction(
&self,
transaction: &mut Transaction,
) -> Result<(), Error>
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.
Sourcepub async fn update_async<Cn: AsyncConnection>(
&mut self,
connection: &Cn,
) -> Result<(), Error>
pub async fn update_async<Cn: AsyncConnection>( &mut self, connection: &Cn, ) -> Result<(), Error>
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);
}Sourcepub fn modify<Cn: Connection, Modifier: FnMut(&mut Self) + Send + Sync>(
&mut self,
connection: &Cn,
modifier: Modifier,
) -> Result<(), Error>
pub 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 modify_async<Cn: AsyncConnection, Modifier: FnMut(&mut Self) + Send + Sync>(
&mut self,
connection: &Cn,
modifier: Modifier,
) -> Result<(), Error>
pub async fn modify_async<Cn: AsyncConnection, 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 fn delete<Cn: Connection>(&self, connection: &Cn) -> Result<(), Error>
pub fn delete<Cn: Connection>(&self, connection: &Cn) -> Result<(), Error>
Removes the document from the collection.
if let Some(document) = MyCollection::get(&42, &db)? {
document.delete(&db)?;
}Sourcepub async fn delete_async<Cn: AsyncConnection>(
&self,
connection: &Cn,
) -> Result<(), Error>
pub async fn delete_async<Cn: AsyncConnection>( &self, connection: &Cn, ) -> Result<(), Error>
Removes the document from the collection.
if let Some(document) = MyCollection::get_async(&42, &db).await? {
document.delete_async(&db).await?;
}Sourcepub fn delete_in_transaction(
&self,
transaction: &mut Transaction,
) -> Result<(), Error>
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.
Sourcepub fn refresh<Cn: Connection>(&mut self, connection: &Cn) -> Result<(), Error>
pub fn refresh<Cn: Connection>(&mut self, connection: &Cn) -> Result<(), Error>
Refreshes this instance from connection. If the document is no longer
present, Error::DocumentNotFound will be returned.
Sourcepub async fn refresh_async<Cn: AsyncConnection>(
&mut self,
connection: &Cn,
) -> Result<(), Error>
pub async fn refresh_async<Cn: AsyncConnection>( &mut self, connection: &Cn, ) -> Result<(), Error>
Refreshes this instance from connection. If the document is no longer
present, Error::DocumentNotFound will be returned.
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§
Source§impl<C> Clone for CollectionDocument<C>
impl<C> Clone for CollectionDocument<C>
Source§fn clone(&self) -> CollectionDocument<C>
fn clone(&self) -> CollectionDocument<C>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<C> Debug for CollectionDocument<C>
impl<C> Debug for CollectionDocument<C>
Source§impl<'de, C> Deserialize<'de> for CollectionDocument<C>
impl<'de, C> Deserialize<'de> for CollectionDocument<C>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<C> HasHeader for CollectionDocument<C>where
C: SerializedCollection,
impl<C> HasHeader for CollectionDocument<C>where
C: SerializedCollection,
Source§impl<'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,
Source§fn name(self) -> Result<NamedReference<'a, C::PrimaryKey>, Error>
fn name(self) -> Result<NamedReference<'a, C::PrimaryKey>, Error>
NamedReference.Source§impl<C> PartialEq for CollectionDocument<C>
impl<C> PartialEq for CollectionDocument<C>
Source§impl<C> Serialize for CollectionDocument<C>
impl<C> Serialize for CollectionDocument<C>
Source§impl<'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,
Source§impl<'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,
Source§impl<'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,
Source§impl<'a, C> TryFrom<&'a OwnedDocument> for CollectionDocument<C>where
C: SerializedCollection,
impl<'a, C> TryFrom<&'a OwnedDocument> for CollectionDocument<C>where
C: SerializedCollection,
impl<C> Eq for CollectionDocument<C>
impl<C> StructuralPartialEq for CollectionDocument<C>where
C: SerializedCollection,
Auto Trait Implementations§
impl<C> Freeze for CollectionDocument<C>
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>
impl<C> UnwindSafe for CollectionDocument<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more