pub trait Update {
// Required methods
fn new() -> Self;
fn into_document(self) -> Result<Document, Error>;
}
Expand description
Used to mark a type as an update for use in queries.
§Examples
Creating an update for user.
use mongod::bson::Document;
use mongod::{Error, Update};
#[derive(Default)]
pub struct UserUpdate {
pub name: Option<String>,
}
impl Update for UserUpdate {
fn new() -> Self {
UserUpdate::default()
}
fn into_document(self) -> Result<Document, Error> {
let mut doc = Document::new();
if let Some(value) = self.name {
doc.insert("name", value);
}
Ok(doc)
}
}
Required Methods§
sourcefn into_document(self) -> Result<Document, Error>
fn into_document(self) -> Result<Document, Error>
Converts a Filter
into a BSON Document
.
Object Safety§
This trait is not object safe.