modio/request/games/
get_game_stats.rs

1use std::future::IntoFuture;
2
3use crate::client::Client;
4use crate::request::{Output, RequestBuilder, Route};
5use crate::response::ResponseFuture;
6use crate::types::games::Statistics;
7use crate::types::id::GameId;
8
9/// Get game stats for a game.
10pub struct GetGameStats<'a> {
11    http: &'a Client,
12    game_id: GameId,
13}
14
15impl<'a> GetGameStats<'a> {
16    pub(crate) const fn new(http: &'a Client, game_id: GameId) -> Self {
17        Self { http, game_id }
18    }
19}
20
21impl IntoFuture for GetGameStats<'_> {
22    type Output = Output<Statistics>;
23    type IntoFuture = ResponseFuture<Statistics>;
24
25    fn into_future(self) -> Self::IntoFuture {
26        let route = Route::GetGameStats {
27            game_id: self.game_id,
28        };
29        match RequestBuilder::from_route(&route).empty() {
30            Ok(req) => self.http.request(req),
31            Err(err) => ResponseFuture::failed(err),
32        }
33    }
34}