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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use std::convert::Into;
pub enum Paths<'a> {
Batch(),
Buckets(),
Bucket(&'a str),
Groups(&'a str),
Group(&'a str, &'a str),
Collections(&'a str),
Collection(&'a str, &'a str),
Records(&'a str, &'a str),
Record(&'a str, &'a str, &'a str),
}
impl <'a> Into <String> for Paths<'a> {
fn into(self) -> String {
match self {
Paths::Batch() =>
format!("/batch"),
Paths::Buckets() =>
format!("/buckets"),
Paths::Bucket(id) =>
format!("/buckets/{id}", id=id),
Paths::Groups(bucket_id) =>
format!("/buckets/{bucket_id}/groups",
bucket_id=bucket_id),
Paths::Group(bucket_id, id) =>
format!("/buckets/{bucket_id}/groups/{id}",
bucket_id=bucket_id, id=id),
Paths::Collections(bucket_id) =>
format!("/buckets/{bucket_id}/collections",
bucket_id=bucket_id),
Paths::Collection(bucket_id, id) =>
format!("/buckets/{bucket_id}/collections/{id}",
bucket_id=bucket_id, id=id),
Paths::Records(bucket_id, collection_id) =>
format!("/buckets/{bucket_id}/collections/{collection_id}/records",
bucket_id=bucket_id, collection_id=collection_id),
Paths::Record(bucket_id, collection_id, id) =>
format!("/buckets/{bucket_id}/collections/{collection_id}/records/{id}",
bucket_id=bucket_id, collection_id=collection_id, id=id),
}
}
}
#[cfg(test)]
mod test_paths{
use super::Paths;
#[test]
fn test_batch_path() {
let path: String = Paths::Batch().into();
assert_eq!(path, "/batch");
}
#[test]
fn test_buckets_path() {
let path: String = Paths::Buckets().into();
assert_eq!(path, "/buckets");
}
#[test]
fn test_bucket_path() {
let path: String = Paths::Bucket("food").into();
assert_eq!(path, "/buckets/food");
}
#[test]
fn test_groups_path() {
let path: String = Paths::Groups("food").into();
assert_eq!(path, "/buckets/food/groups");
}
#[test]
fn test_group_path() {
let path: String = Paths::Group("food", "storage_team").into();
assert_eq!(path, "/buckets/food/groups/storage_team");
}
#[test]
fn test_collections_path() {
let path: String = Paths::Collections("food").into();
assert_eq!(path, "/buckets/food/collections");
}
#[test]
fn test_collection_path() {
let path: String = Paths::Collection("food", "meat").into();
assert_eq!(path, "/buckets/food/collections/meat");
}
#[test]
fn test_records_path() {
let path: String = Paths::Records("food", "meat").into();
assert_eq!(path, "/buckets/food/collections/meat/records");
}
#[test]
fn test_record_path() {
let path: String = Paths::Record("food", "meat", "entrecote").into();
assert_eq!(path, "/buckets/food/collections/meat/records/entrecote");
}
}