> ## Documentation Index
> Fetch the complete documentation index at: https://docs.law4devs.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# Pagination

> Understand manual and automatic pagination in the Rust SDK.

## Overview

Every `list()` / `deadlines()` / `query()` call returns a `Page<T>`. The `iter()` / `iter_deadlines()` methods return a lazy `Stream<T>` that auto-paginates across all pages.

***

## The `Page<T>` Object

```rust theme={null}
let page = client.frameworks.list(Some(1), Some(20)).await?;

page.data            // Vec<T> — items on this page
page.meta.total      // u32 — total items across all pages
page.meta.page       // u32 — current page number
page.meta.per_page   // u32 — items per page
page.meta.pages      // u32 — total number of pages
page.links.next      // Option<String> — URL of next page
page.links.prev      // Option<String> — URL of previous page
page.has_next()      // bool — true if more pages exist
```

**`PageMeta` fields**

| Field      | Type  | Description    |
| ---------- | ----- | -------------- |
| `total`    | `u32` | Total items    |
| `page`     | `u32` | Current page   |
| `per_page` | `u32` | Items per page |
| `pages`    | `u32` | Total pages    |

***

## Manual Pagination

```rust theme={null}
let mut page_num = 1u32;
loop {
    let page = client.frameworks.list(Some(page_num), Some(20)).await?;
    for fw in &page.data {
        println!("{}", fw.name);
    }
    if !page.has_next() { break; }
    page_num += 1;
}
```

***

## Automatic Pagination with `iter()`

`iter()` returns a `Stream` — it fetches the next page only when the current page is exhausted. Use `Box::pin` to make it `Unpin` for `.next().await`:

```rust theme={null}
use futures::StreamExt;

let mut stream = Box::pin(client.frameworks.iter(20));
while let Some(result) = stream.next().await {
    let fw = result?;
    println!("{}", fw.name);
}
```

With a custom page size:

```rust theme={null}
let mut stream = Box::pin(client.articles.iter("gdpr", 50));
while let Some(result) = stream.next().await {
    let a = result?;
    println!("{}", a.title);
}
```

***

## Early Stopping

```rust theme={null}
let mut stream = Box::pin(client.frameworks.iter(20));
while let Some(result) = stream.next().await {
    let fw = result?;
    if fw.slug == "gdpr" {
        println!("Found GDPR");
        break;
    }
}
```

***

## Progress Tracking

```rust theme={null}
let total = client.frameworks.list(None, None).await?.meta.total;
let mut count = 0u32;

let mut stream = Box::pin(client.frameworks.iter(20));
while let Some(result) = stream.next().await {
    let fw = result?;
    count += 1;
    println!("[{count}/{total}] {}", fw.name);
}
```
