rosu_v2/request/
event.rs

1use serde::Serialize;
2
3use crate::{
4    model::event::{EventSort, Events},
5    routing::Route,
6    Osu,
7};
8
9use super::{Query, Request};
10
11/// Get [`Events`].
12#[must_use = "requests must be configured and executed"]
13#[derive(Serialize)]
14pub struct GetEvents<'a> {
15    #[serde(skip)]
16    osu: &'a Osu,
17    sort: Option<EventSort>,
18    #[serde(rename = "cursor_string")]
19    cursor: Option<&'a str>,
20}
21
22impl<'a> GetEvents<'a> {
23    pub(crate) const fn new(osu: &'a Osu) -> Self {
24        Self {
25            osu,
26            sort: None,
27            cursor: None,
28        }
29    }
30
31    /// Sorting option
32    #[inline]
33    pub const fn sort(mut self, sort: EventSort) -> Self {
34        self.sort = Some(sort);
35
36        self
37    }
38
39    /// Cursor for pagination
40    #[inline]
41    pub const fn cursor(mut self, cursor: &'a str) -> Self {
42        self.cursor = Some(cursor);
43
44        self
45    }
46}
47
48into_future! {
49    |self: GetEvents<'_>| -> Events {
50        (
51            Request::with_query(Route::GetEvents, Query::encode(&self)),
52            self.sort,
53        )
54    } => |events, sort: Option<EventSort>| -> Events {
55        events.sort = sort;
56
57        Ok(events)
58    }
59}