#pagination #page #chunk #database #web

paginate

A framework agnostic pagination crate, that is especially suited for databases, slices and collections. Paginate calculates the range of pages indexes, making it ideal for accessing slices, chunking data and querying databases.

13 stable releases

1.1.11 Apr 11, 2022
1.1.8 Jan 21, 2022
1.0.1 Mar 16, 2020

#2 in #pagination

Download history 196/week @ 2023-12-11 30/week @ 2023-12-18 33/week @ 2023-12-25 304/week @ 2024-01-01 619/week @ 2024-01-08 596/week @ 2024-01-15 182/week @ 2024-01-22 117/week @ 2024-01-29 141/week @ 2024-02-05 156/week @ 2024-02-12 137/week @ 2024-02-19 149/week @ 2024-02-26 208/week @ 2024-03-04 175/week @ 2024-03-11 282/week @ 2024-03-18 260/week @ 2024-03-25

936 downloads per month
Used in wanisabi

Apache-2.0

17KB
391 lines

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 Docs 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

No runtime deps