rosu_render/request/
user_preset.rs

1use std::future::IntoFuture;
2
3use serde::{Serialize, Serializer};
4
5use crate::{model::UserPreset, request::Request, routing::Route, ClientError, OrdrClient};
6
7use super::OrdrFuture;
8
9#[derive(Serialize)]
10struct GetUserPresetFields<'a> {
11    key: &'a str,
12    #[serde(serialize_with = "u64_as_str")]
13    discord_id: u64,
14}
15
16#[expect(clippy::trivially_copy_pass_by_ref, reason = "required by serde")]
17fn u64_as_str<S: Serializer>(n: &u64, s: S) -> Result<S::Ok, S::Error> {
18    s.serialize_str(&n.to_string())
19}
20
21/// Get a [`UserPreset`].
22#[must_use]
23pub struct GetUserPreset<'a> {
24    ordr: &'a OrdrClient,
25    fields: GetUserPresetFields<'a>,
26}
27
28impl<'a> GetUserPreset<'a> {
29    pub(crate) const fn new(ordr: &'a OrdrClient, key: &'a str, discord_id: u64) -> Self {
30        Self {
31            ordr,
32            fields: GetUserPresetFields { key, discord_id },
33        }
34    }
35}
36
37impl IntoFuture for &mut GetUserPreset<'_> {
38    type Output = Result<UserPreset, ClientError>;
39    type IntoFuture = OrdrFuture<UserPreset>;
40
41    fn into_future(self) -> Self::IntoFuture {
42        match Request::builder(Route::UserPreset).query(&self.fields) {
43            Ok(builder) => self.ordr.request(builder.build()),
44            Err(err) => OrdrFuture::error(err),
45        }
46    }
47}
48
49impl IntoFuture for GetUserPreset<'_> {
50    type Output = Result<UserPreset, ClientError>;
51    type IntoFuture = OrdrFuture<UserPreset>;
52
53    fn into_future(mut self) -> Self::IntoFuture {
54        (&mut self).into_future()
55    }
56}