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
use crate::Set;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PinnedQueryValues {
Ids(Set<String>),
Docs(Set<PinnedDocument>),
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct PinnedDocument {
_index: String,
_id: String,
}
impl PinnedDocument {
pub fn new<IX, ID>(index: IX, id: ID) -> Self
where
IX: ToString,
ID: ToString,
{
Self {
_index: index.to_string(),
_id: id.to_string(),
}
}
}
impl PinnedQueryValues {
pub fn ids<I>(ids: I) -> Self
where
I: IntoIterator,
I::Item: ToString,
{
Self::Ids(ids.into_iter().map(|x| x.to_string()).collect())
}
pub fn docs<I>(docs: I) -> Self
where
I: IntoIterator<Item = PinnedDocument>,
{
Self::Docs(docs.into_iter().collect())
}
}