Macro mongodm::f[][src]

macro_rules! f {
    ( $field:ident in $type:path ) => { ... };
    ( @ $field:ident in $type:path ) => { ... };
    ( @ @ $field:ident in $type:path ) => { ... };
    ( ( $field:ident in $type:path ) ) => { ... };
    ( ( $field:ident in $type:path ) . $( $rest:tt ).+ ) => { ... };
    ( @ ( $field:ident in $type:path ) . $( $rest:tt ).+ ) => { ... };
    ( @ @ ( $field:ident in $type:path ) . $( $rest:tt ).+ ) => { ... };
}

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);