A framework agnostic pagination crate, that is especially suited for databases, slices and collections. Paginate calculates the range of page indexes, making it ideal for accessing slices, chunking data and querying databases.
Add the following line to your Cargo.toml file:
toml
paginate = "^1"
To iterate over each page:
```rust use paginate::Pages;
fn main() { let totalitems = 100; let itemsperpage = 5; let pages = Pages::new(totalitems, itemsperpage); println!("total pages: {}", pages.pagecount()); for page in pages.intoiter() { println!("offset: {}, total: {}, start: {}, end: {}", page.offset, page.length, page.start, page.end); } } ```
To get the pagination of a specific offset: ```rust use paginate::Pages;
fn main() { let totalitems = 35; let itemsperpage = 5; let pages = Pages::new(totalitems, itemsperpage); let page = pages.withoffset(3); println!("total pages: {}", pages.pagecount()); println!("offset: {}, total: {}, start: {}, end: {}", page.offset, page.length, page.start, page.end); } ```