2023-07-14 10:21:42 +00:00
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
2023-07-13 15:43:05 +00:00
|
|
|
pub struct CursorList<T, C> {
|
|
|
|
pub items: Vec<T>,
|
|
|
|
pub next_cursor: Option<C>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait AsCursor<C> {
|
|
|
|
fn cursor(&self) -> C;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: AsCursor<C>, C> CursorList<T, C> {
|
|
|
|
pub fn new(items: Vec<T>, limit: usize) -> Self {
|
|
|
|
CursorList {
|
|
|
|
next_cursor: items.get(limit - 1).map(|x| x.cursor()),
|
|
|
|
items,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|