Crate paginate

Source
Expand description

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.

§Example

To iterate over each page:

use paginate::Pages;

fn print_pages() {
    let total_items = 100usize;
     let items_per_page = 5usize;
     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 print_test() {
    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);
}

Structs§

  • Defines the properties of a page.
  • Defines the pages to facilitate pagination.