pub trait Action: Sealed + IntoFuture {
// Provided method
fn optional<Value>(
self,
value: Option<Value>,
f: impl FnOnce(Self, Value) -> Self,
) -> Self
where Self: Sized { ... }
}
Expand description
A pending action to execute on the server. The action can be configured via chained methods and
executed via await
(or run
if using the sync client).
Provided Methods§
Sourcefn optional<Value>(
self,
value: Option<Value>,
f: impl FnOnce(Self, Value) -> Self,
) -> Selfwhere
Self: Sized,
fn optional<Value>(
self,
value: Option<Value>,
f: impl FnOnce(Self, Value) -> Self,
) -> Selfwhere
Self: Sized,
If the value is Some
, call the provided function on self
. Convenient for chained
updates with values that need to be set conditionally. For example:
use mongodb::action::Action;
async fn list_my_collections(client: &Client, filter: Option<Document>) -> Result<Vec<String>> {
client.database("my_db")
.list_collection_names()
.optional(filter, |a, f| a.filter(f))
.await
}