xrpl_api/api/
with_pagination.rs

1use crate::Request;
2use serde::{Deserialize, Serialize};
3
4/// Request that allows specifying pagination.
5/// See <https://xrpl.org/markers-and-pagination.html>.
6pub trait WithRequestPagination: Request {
7    fn as_pagination(&self) -> &RequestPagination;
8    fn as_pagination_mut(&mut self) -> &mut RequestPagination;
9
10    fn limit(mut self, limit: u32) -> Self
11    where
12        Self: Sized,
13    {
14        self.as_pagination_mut().limit = Some(limit);
15        self
16    }
17
18    fn marker(mut self, marker: serde_json::Value) -> Self
19    where
20        Self: Sized,
21    {
22        self.as_pagination_mut().marker = Some(marker);
23        self
24    }
25}
26
27/// Response that allows specifying pagination.
28/// See <https://xrpl.org/markers-and-pagination.html>.
29pub trait WithResponsePagination {
30    fn as_pagination(&self) -> &ResponsePagination;
31
32    fn limit(&self) -> Option<u32>
33    where
34        Self: Sized,
35    {
36        self.as_pagination().limit
37    }
38
39    fn marker(&self) -> Option<&serde_json::Value>
40    where
41        Self: Sized,
42    {
43        self.as_pagination().marker.as_ref()
44    }
45}
46
47/// Pagination part of request, see <https://xrpl.org/markers-and-pagination.html>
48#[derive(Default, Debug, Clone, Serialize)]
49pub struct RequestPagination {
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub limit: Option<u32>,
52    /// Marker can be any value including a JSON object, see <https://xrpl.org/markers-and-pagination.html>
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub marker: Option<serde_json::Value>,
55}
56
57/// Pagination part of response, see <https://xrpl.org/markers-and-pagination.html>
58#[derive(Default, Debug, Clone, Deserialize)]
59pub struct ResponsePagination {
60    pub limit: Option<u32>,
61    /// Marker can be any value including a JSON object, see <https://xrpl.org/markers-and-pagination.html>
62    pub marker: Option<serde_json::Value>,
63}