1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/// A helper macro to implement `From` trait from the given query type into the
/// `Query` enum.
#[macro_export]
macro_rules! query {
    ($($kind:ident),*) => (
        $(
            impl<'a> From<$kind<'a>> for Query<'a> {
                fn from(q: $kind<'a>) -> Self {
                    Query::$kind(q)
                }
            }
        )*
    );
}

/// A helper macro to implement `From` trait from the given query type into the
/// `Query` enum, boxing the query.
#[macro_export]
macro_rules! boxed_query {
    ($($kind:ident),*) => (
        $(
            impl<'a> From<$kind<'a>> for Query<'a> {
                fn from(q: $kind<'a>) -> Self {
                    Query::$kind(Box::new(q))
                }
            }
        )*
    );
}

/// A convenience to convert a type of a signed integer into Fauna `Expr`.
#[macro_export]
macro_rules! int_expr {
    ($($kind:ident),*) => (
        $(
            impl<'a> From<$kind> for Number {
                fn from(i: $kind) -> Number {
                    Number::Int(i64::from(i))
                }
            }

            impl<'a> From<$kind> for Expr<'a> {
                fn from(i: $kind) -> Expr<'a> {
                    Expr::Simple(SimpleExpr::Number(i.into()))
                }
            }
        )*
    );
}

/// A convenience to convert a type of a unsigned integer into Fauna `Expr`.
#[macro_export]
macro_rules! uint_expr {
    ($($kind:ident),*) => (
        $(
            impl<'a> From<$kind> for Number {
                fn from(i: $kind) -> Number {
                    Number::UInt(u64::from(i))
                }
            }

            impl<'a> From<$kind> for Expr<'a> {
                fn from(i: $kind) -> Expr<'a> {
                    Expr::Simple(SimpleExpr::Number(i.into()))
                }
            }
        )*
    );
}