ddapi_rs/api/
ddnet.rs

1use crate::api::DDApi;
2use crate::errors::ApiError;
3use crate::scheme::ddnet::*;
4use std::future::Future;
5
6#[allow(dead_code)]
7pub trait DDnetApi {
8    fn master(&self) -> impl Future<Output = Result<Master, ApiError>> + Send;
9    fn custom_master(
10        &self,
11        master: MasterServer,
12    ) -> impl Future<Output = Result<Master, ApiError>> + Send;
13    fn player(&self, player: &str) -> impl Future<Output = Result<Player, ApiError>> + Send;
14    fn query(&self, player: &str) -> impl Future<Output = Result<Vec<Query>, ApiError>> + Send;
15    fn query_map(
16        &self,
17        player: &str,
18    ) -> impl Future<Output = Result<Vec<QueryMap>, ApiError>> + Send;
19    fn query_mapper(
20        &self,
21        player: &str,
22    ) -> impl Future<Output = Result<Vec<QueryMapper>, ApiError>> + Send;
23    fn map(&self, map: &str) -> impl Future<Output = Result<Map, ApiError>> + Send;
24    fn releases_map(&self) -> impl Future<Output = Result<Vec<ReleasesMaps>, ApiError>> + Send;
25    fn status(&self) -> impl Future<Output = Result<Status, ApiError>> + Send;
26}
27
28impl DDnetApi for DDApi {
29    async fn master(&self) -> Result<Master, ApiError> {
30        self.custom_master(MasterServer::One).await
31    }
32
33    async fn custom_master(&self, master: MasterServer) -> Result<Master, ApiError> {
34        self._generator(&Master::api(master)).await
35    }
36
37    async fn player(&self, player: &str) -> Result<Player, ApiError> {
38        self._generator(&Player::api(player)).await
39    }
40    async fn query(&self, player: &str) -> Result<Vec<Query>, ApiError> {
41        self._generator(&Query::api(player)).await
42    }
43
44    async fn query_map(&self, player: &str) -> Result<Vec<QueryMap>, ApiError> {
45        self._generator(&QueryMap::api(player)).await
46    }
47
48    async fn query_mapper(&self, player: &str) -> Result<Vec<QueryMapper>, ApiError> {
49        self._generator(&QueryMapper::api(player)).await
50    }
51
52    async fn map(&self, map: &str) -> Result<Map, ApiError> {
53        self._generator(&Map::api(map)).await
54    }
55    async fn releases_map(&self) -> Result<Vec<ReleasesMaps>, ApiError> {
56        self._generator(&ReleasesMaps::api()).await
57    }
58
59    async fn status(&self) -> Result<Status, ApiError> {
60        self._generator(&Status::api()).await
61    }
62}