macro_rules! f { ( $($tt:tt)* ) => { ... }; }
Expand description
Shorthand for field!
.
Example
use mongodm::mongo::bson::doc;
use mongodm::f;
use mongodm::operator::*;
struct MyModel {
foo: i64,
bar: i64,
lorem: String,
}
// Statically checked
let a = doc! {
And: [
{ f!(foo in MyModel): { Exists: true } },
{
Or: [
{ f!(bar in MyModel): { GreaterThan: 100 } },
{ f!(lorem in MyModel): "ipsum" }
]
},
// dollar and double dollar signs can inserted by prefixing with @
{ f!(@foo in MyModel): f!(@@bar in MyModel) }
]
};
// Hardcoded strings
let b = doc! {
"$and": [
{ "foo": { "$exists": true } },
{
"$or": [
{ "bar": { "$gt": 100 } },
{ "lorem": "ipsum" }
]
},
{ "$foo": "$$bar" }
]
};
// Generated document are identicals
assert_eq!(a, b);