Skip to content

🦀 A framework agnostic pagination crate that is especially suited for databases, slices and collections.

License

Notifications You must be signed in to change notification settings

daniel-samson/paginate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Project Status

crates.io CI CodeFactor codecov book stars - paginate forks - paginate

Installation

Add the following line to your Cargo.toml file:

paginate = "^1"

Examples

To iterate over each page:

use paginate::Pages;

fn main() {
    let total_items = 100;
    let items_per_page = 5;
    let pages = Pages::new(total_items, items_per_page);
    println!("total pages: {}", pages.page_count());
    for page in pages.into_iter() {
        println!("offset: {}, total: {}, start: {}, end: {}", page.offset, page.length, page.start, page.end);
    }
}

To get the pagination of a specific offset:

use paginate::Pages;

fn main() {
    let total_items = 35;
    let items_per_page = 5;
    let pages = Pages::new(total_items, items_per_page);
    let page = pages.with_offset(3);
    println!("total pages: {}", pages.page_count());
    println!("offset: {}, total: {}, start: {}, end: {}", page.offset, page.length, page.start, page.end);
}

Getting help

Contribute

About

🦀 A framework agnostic pagination crate that is especially suited for databases, slices and collections.

Topics

Resources

License

Stars

Watchers

Forks

Languages