use super::{PageResponse, SortAndPageOptions, SortAndVirtualizeOptions, VirtualResponse};
use std::cmp::Ordering;
use std::fmt;
use std::rc::Rc;
pub struct PageContext<T> {
pub response: PageResponse,
pub comparer: Rc<dyn Fn(&T, &T) -> Ordering>,
pub options: SortAndPageOptions,
}
impl<T> PageContext<T> {
pub fn new(response: PageResponse, comparer: Rc<dyn Fn(&T, &T) -> Ordering>, options: SortAndPageOptions) -> Self {
Self { response, comparer, options }
}
pub fn empty() -> Self
where
T: 'static,
{
Self::new(PageResponse::new(0, 0, 0, 0), Rc::new(|_: &T, _: &T| Ordering::Equal), SortAndPageOptions::default())
}
}
impl<T> Clone for PageContext<T> {
fn clone(&self) -> Self {
Self { response: self.response, comparer: self.comparer.clone(), options: self.options }
}
}
impl<T> PartialEq for PageContext<T> {
fn eq(&self, other: &Self) -> bool {
self.response == other.response && Rc::ptr_eq(&self.comparer, &other.comparer) && self.options == other.options
}
}
impl<T> fmt::Debug for PageContext<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PageContext").field("response", &self.response).field("options", &self.options).finish_non_exhaustive()
}
}
pub struct VirtualContext<T> {
pub response: VirtualResponse,
pub comparer: Rc<dyn Fn(&T, &T) -> Ordering>,
pub options: SortAndVirtualizeOptions,
}
impl<T> VirtualContext<T> {
pub fn new(response: VirtualResponse, comparer: Rc<dyn Fn(&T, &T) -> Ordering>, options: SortAndVirtualizeOptions) -> Self {
Self { response, comparer, options }
}
pub fn empty() -> Self
where
T: 'static,
{
Self::new(VirtualResponse::new(0, 0, 0), Rc::new(|_: &T, _: &T| Ordering::Equal), SortAndVirtualizeOptions::default())
}
}
impl<T> Clone for VirtualContext<T> {
fn clone(&self) -> Self {
Self { response: self.response, comparer: self.comparer.clone(), options: self.options }
}
}
impl<T> PartialEq for VirtualContext<T> {
fn eq(&self, other: &Self) -> bool {
self.response == other.response && Rc::ptr_eq(&self.comparer, &other.comparer) && self.options == other.options
}
}
impl<T> fmt::Debug for VirtualContext<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("VirtualContext").field("response", &self.response).field("options", &self.options).finish_non_exhaustive()
}
}