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

/// POST [`Request`] method.
pub trait PostRequest: Sized {
    /// Request body type.
    type Request: Encodable;

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

    /// Get body of request.
    fn body(&self) -> Self::Request;

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

impl<T: PostRequest> PostRequest for &T {
    type Request = T::Request;

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

    fn body(&self) -> Self::Request {
        <T as PostRequest>::body(self)
    }
}

impl<T: PostRequest> Request for Post<T> {
    type Request = T::Request;
    type Response = ();
    type Query = ();

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

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

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

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