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
use chrono::{DateTime, Utc};
use serde::Deserialize;
/// Generic paginated response structure.
///
/// Contains a vector of items and an optional cursor for fetching the next page.
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Page<I> {
data: Vec<I>,
next_cursor: Option<DateTime<Utc>>,
}
impl<I> Page<I> {
/// Vector of items in this page.
///
/// # Examples
///
/// ```no_run
/// # use lnm_sdk::api_v3::models::{Page, Trade};
/// # fn example(page: Page<Trade>) -> Result<(), Box<dyn std::error::Error>> {
/// for item in page.data() {
/// println!("item: {:?}", item);
/// }
/// # Ok(())
/// # }
/// ```
pub fn data(&self) -> &Vec<I> {
&self.data
}
/// Cursor that can be used to fetch the next page of results. `None` if there are no more
/// results.
///
/// # Examples
///
/// ```no_run
/// # use lnm_sdk::api_v3::models::{Page, Trade};
/// # fn example(page: Page<Trade>) -> Result<(), Box<dyn std::error::Error>> {
/// if let Some(cursor) = page.next_cursor() {
/// println!("More items can be fetched using cursor: {cursor}");
/// } else {
/// println!("There are no more items available.");
/// }
/// # Ok(())
/// # }
/// ```
pub fn next_cursor(&self) -> Option<DateTime<Utc>> {
self.next_cursor
}
}
impl<I> From<Page<I>> for Vec<I> {
fn from(value: Page<I>) -> Self {
value.data
}
}