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
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.