Crates.io | pagination |
lib.rs | pagination |
version | 0.3.0 |
source | src |
created_at | 2020-05-28 13:32:33.800514 |
updated_at | 2023-04-20 14:12:12.802761 |
description | a pagination lib for web and database |
homepage | https://github.com/elexing/pagination |
repository | https://github.com/elexing/pagination.git |
max_upload_size | |
id | 247036 |
size | 30,404 |
Pagination
is a page query lib for rust.
use pagination::{
PageParams,
OffsetParams,
DefaultIntoOffset
};
let page_param = PageParams::new(5, 20);
let offset_param = page_param.into_offset();
assert_eq!(offset_param.offset(), 80_u64);
assert_eq!(offset_param.limit(), 20);
use pagination::{
PageRequest,
OffsetRequest,
DefaultIntoOffset
};
struct UserQuery {
name : &'static str,
age : u8
}
let page_req = PageRequest::new(5, 20, UserQuery{name : "alex", "age" : 18});
let offset_req = page_req.into_offset();
assert_eq!(offset_param.offset(), 80_u64);
assert_eq!(offset_param.limit(), 20);
If the page size from user is 0
or greater than max page size
, the DEFAULT_PAGE_SIZE
will be the page size.
The value of DEFAULT_PAGE_SIZE
is 20
, and you can choose the value by the features, page-size-5
,page-size-10
,
page-size-15
, page-size-20
, page-size-30
,page-size-40
, page-size-50
.
use pagination::Page;
let page = Page::new(vec!(10,20,30), 10);
let f1 = page[0];
assert_eq!(f1 , 10);
Licensed under either of these: