Trait couch_rs::document::TypedCouchDocument

source ·
pub trait TypedCouchDocument: DeserializeOwned + Serialize + Sized {
    // Required methods
    fn get_id(&self) -> Cow<'_, str>;
    fn get_rev(&self) -> Cow<'_, str>;
    fn set_rev(&mut self, rev: &str);
    fn set_id(&mut self, id: &str);
    fn merge_ids(&mut self, other: &Self);
}
Expand description

Trait to deal with typed CouchDB documents. For types implementing this trait, the _id and _rev fields on the json data sent/received to/from couchdb are automatically handled by this crate, using get_id and get_rev to get the values (before sending data to couchdb) and set_id and set_rev to set them (after receiving data from couchdb). Note, when reading documents from couchdb directly, if whichever field name is used to store the revision is different from “_rev” (e.g. “my_rev”), the value will always be “the last value of _rev” as updating “_rev is handled by couchdb, not this crate. This should be transparent to users of this crate because set_rev will be called before returning the document to the user, so the user will always see the correct value.

Required Methods§

source

fn get_id(&self) -> Cow<'_, str>

get the _id field

source

fn get_rev(&self) -> Cow<'_, str>

get the _rev field

source

fn set_rev(&mut self, rev: &str)

set the _rev field

source

fn set_id(&mut self, id: &str)

set the _id field

source

fn merge_ids(&mut self, other: &Self)

merge the _id and _rev from the other document with this one

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl TypedCouchDocument for Value

Allows dealing with _id and _rev fields in untyped (Value) documents

source§

fn get_id(&self) -> Cow<'_, str>

source§

fn get_rev(&self) -> Cow<'_, str>

source§

fn set_rev(&mut self, rev: &str)

source§

fn set_id(&mut self, id: &str)

source§

fn merge_ids(&mut self, other: &Self)

Implementors§