rosu_render/request/
skin_list.rs

1use std::future::IntoFuture;
2
3use serde::Serialize;
4
5use crate::{model::SkinList, request::Request, routing::Route, ClientError, OrdrClient};
6
7use super::OrdrFuture;
8
9#[derive(Serialize)]
10struct GetSkinListFields<'a> {
11    #[serde(rename = "pageSize")]
12    page_size: Option<u32>,
13    page: Option<u32>,
14    search: Option<&'a str>,
15}
16
17/// Get a [`SkinList`].
18#[must_use]
19pub struct GetSkinList<'a> {
20    ordr: &'a OrdrClient,
21    fields: GetSkinListFields<'a>,
22}
23
24impl<'a> GetSkinList<'a> {
25    pub(crate) const fn new(ordr: &'a OrdrClient) -> Self {
26        Self {
27            ordr,
28            fields: GetSkinListFields {
29                page_size: None,
30                page: None,
31                search: None,
32            },
33        }
34    }
35
36    /// The number of skins the API will return you in the page. If not specified, 100 is the default.
37    pub fn page_size(&mut self, page_size: u32) -> &mut Self {
38        self.fields.page_size = Some(page_size);
39        self.fields.page.get_or_insert(1);
40
41        self
42    }
43
44    /// The page.
45    pub fn page(&mut self, page: u32) -> &mut Self {
46        self.fields.page = Some(page);
47
48        self
49    }
50
51    /// Get the skins that matches the most your string.
52    pub fn search(&mut self, search: &'a str) -> &mut Self {
53        self.fields.search = Some(search);
54
55        self
56    }
57}
58
59impl IntoFuture for &mut GetSkinList<'_> {
60    type Output = Result<SkinList, ClientError>;
61    type IntoFuture = OrdrFuture<SkinList>;
62
63    fn into_future(self) -> Self::IntoFuture {
64        match Request::builder(Route::SkinList).query(&self.fields) {
65            Ok(builder) => self.ordr.request(builder.build()),
66            Err(err) => OrdrFuture::error(err),
67        }
68    }
69}
70
71impl IntoFuture for GetSkinList<'_> {
72    type Output = Result<SkinList, ClientError>;
73    type IntoFuture = OrdrFuture<SkinList>;
74
75    fn into_future(mut self) -> Self::IntoFuture {
76        (&mut self).into_future()
77    }
78}