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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use super::args::Args;
use crate::{Func, Query};
use ql2::term::TermType;
use serde_json::Value;
pub trait Arg {
fn into_query(self) -> Query;
}
impl Arg for Query {
fn into_query(self) -> Query {
Self::new(TermType::Funcall).with_arg(self)
}
}
#[allow(array_into_iter)]
#[allow(clippy::into_iter_on_ref)]
impl<const N: usize> Arg for Args<([Query; N], Query)> {
fn into_query(self) -> Query {
let Args((arr, expr)) = self;
let mut query = expr.into_query();
for arg in arr.into_iter().cloned() {
query = query.with_arg(arg);
}
query
}
}
#[allow(array_into_iter)]
#[allow(clippy::into_iter_on_ref)]
impl<T, const N: usize> Arg for Args<([T; N], Query)>
where
T: Into<Value> + Clone,
{
fn into_query(self) -> Query {
let Args((arr, expr)) = self;
let mut query = expr.into_query();
for arg in arr.into_iter().cloned() {
let arg = Query::from_json(arg.into());
query = query.with_arg(arg);
}
query
}
}
impl Arg for Args<(Query, Func)> {
fn into_query(self) -> Query {
let Args((query, Func(func))) = self;
func.into_query().with_arg(query)
}
}
impl Arg for Func {
fn into_query(self) -> Query {
let Func(func) = self;
func.into_query()
}
}
#[allow(array_into_iter)]
#[allow(clippy::into_iter_on_ref)]
impl<const N: usize> Arg for Args<([Query; N], Func)> {
fn into_query(self) -> Query {
let Args((arr, Func(func))) = self;
let mut query = func.into_query();
for arg in arr.into_iter().cloned() {
query = query.with_arg(arg);
}
query
}
}
#[allow(array_into_iter)]
#[allow(clippy::into_iter_on_ref)]
impl<T, const N: usize> Arg for Args<([T; N], Func)>
where
T: Into<Value> + Clone,
{
fn into_query(self) -> Query {
let Args((arr, Func(func))) = self;
let mut query = func.into_query();
for arg in arr.into_iter().cloned() {
let arg = Query::from_json(arg.into());
query = query.with_arg(arg);
}
query
}
}