Skip to main content

Module pagination

Module pagination 

Source
Expand description

Offset pagination primitives: a query extractor for the request side and a uniform envelope for the response side.

#[Get("/")]
async fn list(&self, #[Query] page: PageParams, svc: Inject<UserService>)
    -> Json<Page<User>>
{
    let total = svc.count().await;
    let rows  = svc.list(page.limit(), page.offset()).await;
    Json(Page::new(rows, page, total))
}

PageParams deserializes straight from the query string (?page=2&per_page=50) and is clamped on read, so a handler can never receive a zero page, a negative offset, or an unbounded per_page that lets a client ask for the whole table.

Structs§

Page
A page of results plus the metadata a client needs to walk the rest.
PageParams
Query parameters for an offset-paginated list endpoint.

Constants§

DEFAULT_PER_PAGE
Default page size when the client omits per_page.
MAX_PER_PAGE
Largest page size a client may request; larger values are clamped down so per_page can never be weaponised into a full-table scan.