1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Generic pagination helpers behind the `stream` feature.
//!
//! Most CNB list endpoints take `page` + `page_size` query parameters and
//! return a JSON array of items (sometimes wrapped in a typed `Vec<T>` DTO).
//! [`paginate`] turns any such "give me page N" closure into a
//! `futures::Stream` that transparently advances pages until the server
//! returns a short page or an empty page.
//!
//! Generated resource modules expose `*_stream(...)` variants that wrap their
//! single-page method with this helper.
//!
//! # Example
//!
//! ```ignore
//! use cnb::{ApiClient, pagination::paginate};
//! use futures::StreamExt;
//!
//! let client = ApiClient::new()?;
//! let stream = paginate(50, |page, page_size| {
//! let c = client.clone();
//! async move {
//! let q = cnb::repositories::GetReposQuery::new()
//! .page(page)
//! .page_size(page_size);
//! c.repositories().get_repos(&q).await
//! }
//! });
//! futures::pin_mut!(stream);
//! while let Some(item) = stream.next().await {
//! let item = item?;
//! println!("{item:?}");
//! }
//! # Ok::<_, cnb::ApiError>(())
//! ```
use Future;
use crateResult;
/// Paginate a list endpoint into an `impl Stream<Item = Result<T>>`.
///
/// `page_size` is forwarded to the closure. Pagination stops when the server
/// returns fewer than `page_size` items or an empty page. Errors short-circuit
/// the stream.