Skip to content

Commit 56e28e5

Browse files
authored
add PaginationParams::new_first_page (#1528)
Allows construction of a `PaginationParams` without having to do a `Serialize`/`Deserialize` roundtrip.
1 parent 63c0e49 commit 56e28e5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

dropshot/src/pagination.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,26 @@ where
234234

235235
/// Client-requested limit on page size (optional)
236236
///
237-
/// Consumers should use
238-
/// [`RequestContext`][crate::handler::RequestContext::page_limit()]
239-
/// to access this value.
237+
/// While this is publicly settable via the `Deserialize` implementation, it
238+
/// is untrusted and therefore hidden from users. Consumers should instead
239+
/// use [`RequestContext`][crate::handler::RequestContext::page_limit()],
240+
/// which has gone through validation against the server config, to access
241+
/// this value.
240242
pub(crate) limit: Option<NonZeroU32>,
241243
}
242244

245+
impl<ScanParams, PageSelector> PaginationParams<ScanParams, PageSelector>
246+
where
247+
ScanParams: DeserializeOwned,
248+
PageSelector: DeserializeOwned + Serialize,
249+
{
250+
/// Construct a new [`PaginationParams`] representing the first page of a
251+
/// scan.
252+
pub fn new_first_page(p: ScanParams, limit: Option<NonZeroU32>) -> Self {
253+
Self { page: WhichPage::First(p), limit }
254+
}
255+
}
256+
243257
pub(crate) const PAGINATION_PARAM_SENTINEL: &str =
244258
"x-dropshot-pagination-param";
245259
pub(crate) const PAGINATION_EXTENSION: &str = "x-dropshot-pagination";

0 commit comments

Comments
 (0)