mesa_dev/models/pagination.rs
1//! Pagination types.
2//!
3//! This module provides [`PaginationParams`] for manual page-by-page control
4//! and the [`Paginated`] trait that list response types implement for automatic
5//! pagination via [`PageStream`](crate::PageStream).
6
7use serde::Serialize;
8
9/// Query parameters for paginated endpoints.
10#[derive(Debug, Clone, Default, Serialize)]
11pub struct PaginationParams {
12 /// Cursor for the next page.
13 #[serde(skip_serializing_if = "Option::is_none")]
14 pub cursor: Option<String>,
15 /// Maximum number of results per page.
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub limit: Option<u32>,
18}
19
20/// Trait for paginated API response types.
21///
22/// Implement this trait on your response type to enable automatic pagination
23/// via [`PageStream`](crate::PageStream). The SDK provides implementations for
24/// all built-in list response types.
25///
26/// # Required methods
27///
28/// - [`items`](Self::items) — Extract the items from this page (consumes `self`)
29/// - [`next_cursor`](Self::next_cursor) — Return the cursor string for fetching the next page
30/// - [`has_more`](Self::has_more) — Return whether more pages exist
31pub trait Paginated {
32 /// The individual item type within a page.
33 type Item: Send + Sync;
34
35 /// Returns the items from this page.
36 fn items(self) -> Vec<Self::Item>;
37
38 /// Returns the cursor for the next page, if any.
39 fn next_cursor(&self) -> Option<&str>;
40
41 /// Returns whether more pages are available.
42 fn has_more(&self) -> bool;
43}