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
use serde::de::DeserializeOwned;
use serde::Serialize;

/// API request.
///
/// Request type is [`Serialize`] with associated response type [`Response`][`Request::Response`] and endpoint name [`ENDPOINT`][`Request::ENDPOINT`].
pub trait Request: Serialize {
    /// Response type of this request.
    type Response: DeserializeOwned;
    /// The name of the corresponding endpoint.
    const ENDPOINT: &'static str;
}

impl<R: ?Sized> Request for &'_ R
where
    R: Request,
{
    type Response = R::Response;
    const ENDPOINT: &'static str = R::ENDPOINT;
}

impl<R: ?Sized> Request for &'_ mut R
where
    R: Request,
{
    type Response = R::Response;
    const ENDPOINT: &'static str = R::ENDPOINT;
}

impl<R: ?Sized> Request for Box<R>
where
    R: Request,
{
    type Response = R::Response;
    const ENDPOINT: &'static str = R::ENDPOINT;
}

/// [`Request`] that requires a file to upload.
pub trait UploadFileRequest: Request {}

impl<R: ?Sized> UploadFileRequest for &'_ R where R: UploadFileRequest {}
impl<R: ?Sized> UploadFileRequest for &'_ mut R where R: UploadFileRequest {}
impl<R: ?Sized> UploadFileRequest for Box<R> where R: UploadFileRequest {}