iota_sdk_graphql_client/
pagination.rs1use crate::query_types::PageInfo;
5
6#[derive(Clone, Debug)]
8pub struct Page<T> {
9 pub page_info: PageInfo,
12 pub data: Vec<T>,
14}
15
16impl<T> Page<T> {
17 pub fn page_info(&self) -> &PageInfo {
19 &self.page_info
20 }
21
22 pub fn data(&self) -> &[T] {
24 &self.data
25 }
26
27 pub fn new(page_info: PageInfo, data: Vec<T>) -> Self {
29 Self { page_info, data }
30 }
31
32 pub fn is_empty(&self) -> bool {
34 self.data.is_empty()
35 }
36
37 pub fn new_empty() -> Self {
39 Self::new(PageInfo::default(), vec![])
40 }
41
42 pub fn into_parts(self) -> (PageInfo, Vec<T>) {
44 (self.page_info, self.data)
45 }
46
47 pub fn map<F: Fn(T) -> U, U>(self, map_fn: F) -> Page<U> {
48 Page {
49 page_info: self.page_info,
50 data: self.data.into_iter().map(map_fn).collect(),
51 }
52 }
53}
54
55#[derive(Clone, Debug, Default)]
57pub enum Direction {
58 #[default]
59 Forward,
60 Backward,
61}
62
63#[derive(Clone, Debug, Default)]
66pub struct PaginationFilter {
67 pub direction: Direction,
69 pub cursor: Option<String>,
71 pub limit: Option<i32>,
74}
75
76#[derive(Clone, Debug, Default)]
77pub struct PaginationFilterResponse {
78 pub after: Option<String>,
79 pub before: Option<String>,
80 pub first: Option<i32>,
81 pub last: Option<i32>,
82}