18 lines
364 B
Rust
18 lines
364 B
Rust
|
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,
|
||
|
}
|
||
|
}
|
||
|
}
|