| Crates.io | paging-stream |
| lib.rs | paging-stream |
| version | 0.1.0 |
| created_at | 2025-05-24 07:03:29.956937+00 |
| updated_at | 2025-05-24 07:03:29.956937+00 |
| description | A utility to consume paginated data sources as a `futures::Stream` |
| homepage | |
| repository | https://github.com/jakob-lilliemarck/paging-stream |
| max_upload_size | |
| id | 1687100 |
| size | 32,623 |
A utility to make it trivial to expose paginated resources as futures::Stream.
Use this crate to hide repository implementation details from client code. Client code may instead request the full collection at once and then the stream will lazily paginate over it, yielding results in order as they become available.
[dependencies]
paging-stream = "0.1.0"
use futures::{Stream, StreamExt};
use paging_stream::{Paginated, PagingStream};
impl Paginated for YourRepository {
type Params = SomeParams;
type Item = usize;
type Error = ();
fn fetch_page(
&self,
params: Self::Params,
) -> impl Future<Output = Result<(Vec<Self::Item>, Option<Self::Params>), Self::Error>>
+ Send
+ 'static {
async move {
// Your async request here
}
}
}
#[tokio::main]
async fn main() {
let repository = SomeRepository { /* whatever fields */};
let params = SomeParams { /* pagination params */};
let mut stream = PagingStream::new(repository, params);
while let Some(value) = stream.next().await {
// Consume the stream and do something with the values
}
}