pegination

Crates.iopegination
lib.rspegination
version0.6.0
sourcesrc
created_at2022-12-26 19:19:52.158542
updated_at2024-04-18 09:59:01.425031
descriptionPegination is implementation of cursor pagination
homepagehttps://pepe.team
repositoryhttps://github.com/crypto-pepe/pepe-rs
max_upload_size
id745913
size19,495
saehrimnir (stupid-boar)

documentation

README

Pegination

Implementation of cursor pagination. See the tests for details.

Requirements

1. Structure SourceRequest

Source request sent to API

#[derive(Debug, Clone)]
struct SourceRequest {}

2. Structure Filters

Data source filters, excludes limit and offset

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
struct Filters {}

3. Structure Item

Data source entity

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
struct Item {}

4. Entity Error

enum AppError {}

Required implementations

1. SourceRequest to Request<Filters> transormation

impl TryFrom<SourceRequest> for Request<Filters> {}

2. DataSource

trait DataSource<Item, Filters: Clone + PartialEq, OffsetValue: Clone>

Usage

Having all of the stuff described above, you can use pagination function this way:

const DEFAULT_LIMIT: u16 = 100;

let paginated_data = pagination::<Item, Filters, OffsetValue, AppError>(data_source, source_request, DEFAULT_LIMIT).await?;
// {
//   "last_cursor": null,
//   "has_next_page": false,
//   "data": [
//     ..items
//   ]
// }
Commit count: 0

cargo fmt