1use std::marker::PhantomData;
2
3pub trait QueryBuilder: Sized {
5 fn add_query(&mut self, key: String, value: String);
7
8 fn query(mut self, key: impl Into<String>, value: impl ToString) -> Self {
10 self.add_query(key.into(), value.to_string());
11 self
12 }
13
14 fn query_opt(mut self, key: impl Into<String>, value: Option<impl ToString>) -> Self {
16 if let Some(v) = value {
17 self.add_query(key.into(), v.to_string());
18 }
19 self
20 }
21
22 fn query_many<I, V>(self, key: impl Into<String>, values: I) -> Self
24 where
25 I: IntoIterator<Item = V>,
26 V: ToString,
27 {
28 let key = key.into();
29 let mut result = self;
30 for value in values {
31 result.add_query(key.clone(), value.to_string());
32 }
33 result
34 }
35
36 fn query_many_opt<I, V>(self, key: impl Into<String>, values: Option<I>) -> Self
38 where
39 I: IntoIterator<Item = V>,
40 V: ToString,
41 {
42 if let Some(values) = values {
43 self.query_many(key, values)
44 } else {
45 self
46 }
47 }
48}
49
50pub struct TypedRequest<T> {
52 pub(crate) _marker: PhantomData<T>,
53}
54
55impl<T> TypedRequest<T> {
56 pub fn new() -> Self {
57 Self {
58 _marker: PhantomData,
59 }
60 }
61}
62
63impl<T> Default for TypedRequest<T> {
64 fn default() -> Self {
65 Self::new()
66 }
67}