Crates.io | pegination |
lib.rs | pegination |
version | 0.6.0 |
source | src |
created_at | 2022-12-26 19:19:52.158542 |
updated_at | 2024-04-18 09:59:01.425031 |
description | Pegination is implementation of cursor pagination |
homepage | https://pepe.team |
repository | https://github.com/crypto-pepe/pepe-rs |
max_upload_size | |
id | 745913 |
size | 19,495 |
Implementation of cursor pagination. See the tests for details.
SourceRequest
Source request sent to API
#[derive(Debug, Clone)]
struct SourceRequest {}
Filters
Data source filters, excludes limit and offset
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
struct Filters {}
Item
Data source entity
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
struct Item {}
Error
enum AppError {}
SourceRequest
to Request<Filters>
transormationimpl TryFrom<SourceRequest> for Request<Filters> {}
DataSource
trait DataSource<Item, Filters: Clone + PartialEq, OffsetValue: Clone>
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
// ]
// }