pagination

Crates.iopagination
lib.rspagination
version0.3.0
sourcesrc
created_at2020-05-28 13:32:33.800514
updated_at2023-04-20 14:12:12.802761
descriptiona pagination lib for web and database
homepagehttps://github.com/elexing/pagination
repositoryhttps://github.com/elexing/pagination.git
max_upload_size
id247036
size30,404
青橙 (elexing)

documentation

https://github.com/elexing/pagination

README

What

Pagination is a page query lib for rust.

Usage

Build pageable request param

Only pagination params

 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);

Support complex params

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);

Default page size

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.

Wrap the database result


use pagination::Page;

let page = Page::new(vec!(10,20,30), 10);
let f1 = page[0];
assert_eq!(f1 , 10);

License

Licensed under either of these:

Commit count: 9

cargo fmt