{"id":21586011,"url":"https://github.com/magiclen/paginator","last_synced_at":"2025-04-10T20:15:05.978Z","repository":{"id":57652025,"uuid":"286448688","full_name":"magiclen/paginator","owner":"magiclen","description":"This crate is used for generating pagination bar.","archived":false,"fork":false,"pushed_at":"2023-09-10T03:19:21.000Z","size":48,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T17:55:18.453Z","etag":null,"topics":["pagination","paginator","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/magiclen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-10T10:48:21.000Z","updated_at":"2023-02-19T23:58:38.000Z","dependencies_parsed_at":"2024-11-24T18:01:13.804Z","dependency_job_id":null,"html_url":"https://github.com/magiclen/paginator","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"d8cabd192e09d87bcbcd3ef86f8bdd63db91c7c3"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fpaginator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fpaginator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fpaginator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fpaginator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magiclen","download_url":"https://codeload.github.com/magiclen/paginator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248144070,"owners_count":21054865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pagination","paginator","rust"],"created_at":"2024-11-24T15:12:23.236Z","updated_at":"2025-04-10T20:15:05.959Z","avatar_url":"https://github.com/magiclen.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Paginator\n====================\n\n[![CI](https://github.com/magiclen/paginator/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/paginator/actions/workflows/ci.yml)\n\nThis crate is used for generating pagination bar on webpages or other UIs.\n\n## Examples\n\n#### Creating a Pagination Bar Which Has 5 Pages and Is on Page 1\n\n```rust\nuse paginator::{Paginator, PageItem};\n\nuse core::fmt::Write;\n\nlet paginator = Paginator::builder(5).current_page(1).build_paginator().unwrap();\n\nlet mut html = String::new();\n\nfor page_item in paginator.paginate() {\n    match page_item {\n        PageItem::Prev(page) =\u003e {\n            // `PageItem::Prev` variant is used when the `has_prev` option is not set to `YesNoDepends::No`.\n\n            html.write_fmt(format_args!(\"\u003cli\u003e\u003ca href=\\\"/page/{page}\\\"\u003e\u0026laquo;\u003c/a\u003e\u003c/li\u003e\", page = page)).unwrap();\n        }\n        PageItem::Page(page) =\u003e {\n            html.write_fmt(format_args!(\"\u003cli\u003e\u003ca href=\\\"/page/{page}\\\"\u003e{page}\u003c/a\u003e\u003c/li\u003e\", page = page)).unwrap();\n        }\n        PageItem::CurrentPage(page) =\u003e {\n            html.write_fmt(format_args!(\"\u003cli\u003e{page}\u003c/li\u003e\", page = page)).unwrap();\n        }\n        PageItem::Ignore =\u003e {\n            html.push_str(\"\u003cli\u003e...\u003c/li\u003e\");\n        }\n        PageItem::Next(page) =\u003e {\n            // `PageItem::Next` variant is used when the `has_next` option is not set to `YesNoDepends::No`.\n\n            html.write_fmt(format_args!(\"\u003cli\u003e\u003ca href=\\\"/page/{page}\\\"\u003e\u0026raquo;\u003c/a\u003e\u003c/li\u003e\", page = page)).unwrap();\n        }\n        _ =\u003e {\n            // `PageItem::ReservedPrev` or `PageItem::ReservedNext` variant is used only when the `has_prev` option or the `has_next` option is set to `YesNoDepends::Yes`.\n        }\n    }\n}\n```\n\n#### Creating Pagination Bars Which Has 2 Pages for Different Current Pages\n\n```rust\nuse paginator::{Paginator, PageItem};\n\nlet mut paginator_iter = Paginator::builder(2).build_paginator_iter().unwrap();\n\nfor page_item in paginator_iter.next().unwrap().paginate() {\n    // current_page == 1\n}\n\nfor page_item in paginator_iter.next().unwrap().paginate() {\n    // current_page == 2\n}\n```\n\n## Pagination Rules\n\nBefore building up a `Paginator`, there is an important option, `max_item_count`, can be set via `PaginatorBuilder`. This option can limit the count of items on the pagination bar. This crate **ignores** page items far away from the current page item to stick to the count limit of items. The first/last n items can be additionally reserved.\n\nLook at the following code for more details.\n\n```rust\nuse paginator::{Paginator, page_items_to_string};\n\nlet mut p = Paginator::builder(8).max_item_count(9).start_size(1).end_size(1).build_paginator_iter().unwrap();\n\nassert_eq!(\"1* 2 3 4 5 6 7 8 \u003e\", page_items_to_string(p.next().unwrap().paginate().as_slice()));\nassert_eq!(\"\u003c 1 2* 3 4 5 ... 8 \u003e\", page_items_to_string(p.next().unwrap().paginate().as_slice()));\nassert_eq!(\"\u003c 1 2 3* 4 5 ... 8 \u003e\", page_items_to_string(p.next().unwrap().paginate().as_slice()));\nassert_eq!(\"\u003c 1 2 3 4* 5 ... 8 \u003e\", page_items_to_string(p.next().unwrap().paginate().as_slice()));\nassert_eq!(\"\u003c 1 ... 4 5* 6 7 8 \u003e\", page_items_to_string(p.next().unwrap().paginate().as_slice()));\nassert_eq!(\"\u003c 1 ... 4 5 6* 7 8 \u003e\", page_items_to_string(p.next().unwrap().paginate().as_slice()));\nassert_eq!(\"\u003c 1 ... 4 5 6 7* 8 \u003e\", page_items_to_string(p.next().unwrap().paginate().as_slice()));\nassert_eq!(\"\u003c 1 2 3 4 5 6 7 8*\", page_items_to_string(p.next().unwrap().paginate().as_slice()));\n```\n\n## No Std\n\nDisable the default features to compile this crate without std.\n\n```toml\n[dependencies.paginator]\nversion = \"*\"\ndefault-features = false\n```\n\n## Crates.io\n\nhttps://crates.io/crates/paginator\n\n## Documentation\n\nhttps://docs.rs/paginator\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagiclen%2Fpaginator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagiclen%2Fpaginator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagiclen%2Fpaginator/lists"}