misskey_core/
api.rs

1use serde::de::DeserializeOwned;
2use serde::Serialize;
3
4/// API request.
5///
6/// Request type is [`Serialize`] with associated response type [`Response`][`Request::Response`] and endpoint name [`ENDPOINT`][`Request::ENDPOINT`].
7pub trait Request: Serialize {
8    /// Response type of this request.
9    type Response: DeserializeOwned;
10    /// The name of the corresponding endpoint.
11    const ENDPOINT: &'static str;
12}
13
14impl<R: ?Sized> Request for &'_ R
15where
16    R: Request,
17{
18    type Response = R::Response;
19    const ENDPOINT: &'static str = R::ENDPOINT;
20}
21
22impl<R: ?Sized> Request for &'_ mut R
23where
24    R: Request,
25{
26    type Response = R::Response;
27    const ENDPOINT: &'static str = R::ENDPOINT;
28}
29
30impl<R: ?Sized> Request for Box<R>
31where
32    R: Request,
33{
34    type Response = R::Response;
35    const ENDPOINT: &'static str = R::ENDPOINT;
36}
37
38/// [`Request`] that requires a file to upload.
39pub trait UploadFileRequest: Request {}
40
41impl<R: ?Sized> UploadFileRequest for &'_ R where R: UploadFileRequest {}
42impl<R: ?Sized> UploadFileRequest for &'_ mut R where R: UploadFileRequest {}
43impl<R: ?Sized> UploadFileRequest for Box<R> where R: UploadFileRequest {}