ferroui_dynamic_data/cache/
page_context.rs1use super::{PageResponse, SortAndPageOptions, SortAndVirtualizeOptions, VirtualResponse};
6use std::cmp::Ordering;
7use std::fmt;
8use std::rc::Rc;
9
10pub struct PageContext<T> {
13 pub response: PageResponse,
15 pub comparer: Rc<dyn Fn(&T, &T) -> Ordering>,
17 pub options: SortAndPageOptions,
19}
20
21impl<T> PageContext<T> {
22 pub fn new(response: PageResponse, comparer: Rc<dyn Fn(&T, &T) -> Ordering>, options: SortAndPageOptions) -> Self {
24 Self { response, comparer, options }
25 }
26
27 pub fn empty() -> Self
32 where
33 T: 'static,
34 {
35 Self::new(PageResponse::new(0, 0, 0, 0), Rc::new(|_: &T, _: &T| Ordering::Equal), SortAndPageOptions::default())
36 }
37}
38
39impl<T> Clone for PageContext<T> {
40 fn clone(&self) -> Self {
41 Self { response: self.response, comparer: self.comparer.clone(), options: self.options }
42 }
43}
44
45impl<T> PartialEq for PageContext<T> {
46 fn eq(&self, other: &Self) -> bool {
48 self.response == other.response && Rc::ptr_eq(&self.comparer, &other.comparer) && self.options == other.options
49 }
50}
51
52impl<T> fmt::Debug for PageContext<T> {
53 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 f.debug_struct("PageContext").field("response", &self.response).field("options", &self.options).finish_non_exhaustive()
55 }
56}
57
58pub struct VirtualContext<T> {
61 pub response: VirtualResponse,
63 pub comparer: Rc<dyn Fn(&T, &T) -> Ordering>,
65 pub options: SortAndVirtualizeOptions,
67}
68
69impl<T> VirtualContext<T> {
70 pub fn new(response: VirtualResponse, comparer: Rc<dyn Fn(&T, &T) -> Ordering>, options: SortAndVirtualizeOptions) -> Self {
72 Self { response, comparer, options }
73 }
74
75 pub fn empty() -> Self
80 where
81 T: 'static,
82 {
83 Self::new(VirtualResponse::new(0, 0, 0), Rc::new(|_: &T, _: &T| Ordering::Equal), SortAndVirtualizeOptions::default())
84 }
85}
86
87impl<T> Clone for VirtualContext<T> {
88 fn clone(&self) -> Self {
89 Self { response: self.response, comparer: self.comparer.clone(), options: self.options }
90 }
91}
92
93impl<T> PartialEq for VirtualContext<T> {
94 fn eq(&self, other: &Self) -> bool {
96 self.response == other.response && Rc::ptr_eq(&self.comparer, &other.comparer) && self.options == other.options
97 }
98}
99
100impl<T> fmt::Debug for VirtualContext<T> {
101 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
102 f.debug_struct("VirtualContext").field("response", &self.response).field("options", &self.options).finish_non_exhaustive()
103 }
104}