mabel/src/cursor.rs

21 lines
408 B
Rust

use serde::Serialize;
#[derive(Serialize)]
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,
}
}
}