1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::Request;
use serde::{Deserialize, Serialize};

/// Request that allows specifying pagination.
/// See <https://xrpl.org/markers-and-pagination.html>.
pub trait WithRequestPagination: Request {
    fn as_pagination(&self) -> &RequestPagination;
    fn as_pagination_mut(&mut self) -> &mut RequestPagination;

    fn limit(mut self, limit: u32) -> Self
    where
        Self: Sized,
    {
        self.as_pagination_mut().limit = Some(limit);
        self
    }

    fn marker(mut self, marker: serde_json::Value) -> Self
    where
        Self: Sized,
    {
        self.as_pagination_mut().marker = Some(marker);
        self
    }
}

/// Response that allows specifying pagination.
/// See <https://xrpl.org/markers-and-pagination.html>.
pub trait WithResponsePagination {
    fn as_pagination(&self) -> &ResponsePagination;

    fn limit(&self) -> Option<u32>
    where
        Self: Sized,
    {
        self.as_pagination().limit
    }

    fn marker(&self) -> Option<&serde_json::Value>
    where
        Self: Sized,
    {
        self.as_pagination().marker.as_ref()
    }
}

/// Pagination part of request, see <https://xrpl.org/markers-and-pagination.html>
#[derive(Default, Debug, Clone, Serialize)]
pub struct RequestPagination {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    /// Marker can be any value including a JSON object, see <https://xrpl.org/markers-and-pagination.html>
    #[serde(skip_serializing_if = "Option::is_none")]
    pub marker: Option<serde_json::Value>,
}

/// Pagination part of response, see <https://xrpl.org/markers-and-pagination.html>
#[derive(Default, Debug, Clone, Deserialize)]
pub struct ResponsePagination {
    pub limit: Option<u32>,
    /// Marker can be any value including a JSON object, see <https://xrpl.org/markers-and-pagination.html>
    pub marker: Option<serde_json::Value>,
}