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
use super::*;

/// GET [`Request`] method.
///
/// The GET method requests a representation of the specified resource. Requests using GET should
/// only retrieve data.
pub trait GetRequest: Sized {
    /// Response type and encoding.
    type Response: Decodable;

    /// Query type.
    type Query: ToQuery;

    /// URI path.
    fn path(&self) -> Cow<'_, str>;

    /// Query parameters.
    fn query(&self) -> Self::Query;

    /// Turn this into a [`Request`].
    fn request(self) -> Get<Self> {
        self.into()
    }
}

impl<T: GetRequest> GetRequest for &T {
    type Response = T::Response;
    type Query = T::Query;

    fn path(&self) -> Cow<'_, str> {
        <T as GetRequest>::path(self)
    }

    fn query(&self) -> Self::Query {
        <T as GetRequest>::query(self)
    }
}

impl<T: GetRequest> Request for Get<T> {
    type Request = ();
    type Response = T::Response;
    type Query = T::Query;

    fn path(&self) -> Cow<'_, str> {
        self.inner.path()
    }

    fn body(&self) -> Self::Request {}

    fn query(&self) -> Self::Query {
        self.inner.query()
    }

    fn method(&self) -> Method {
        Method::Get
    }
}