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

# Rust

> Rust client for the Dune Data API

The published [`duners` crate](https://crates.io/crates/duners) runs queries asynchronously and deserializes results into your own row types.

## Installation

```bash theme={null}
cargo add duners
cargo add serde --features derive
cargo add tokio --features macros,rt-multi-thread
```

Set `DUNE_API_KEY` in your environment before running the example.

## Run SQL

```rust theme={null}
use duners::{DuneClient, DuneRequestError};
use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Row {
    value: u64,
}

#[tokio::main]
async fn main() -> Result<(), DuneRequestError> {
    let client = DuneClient::from_env();
    let result = client.run_sql::<Row>("SELECT 1 AS value", None, None).await?;
    println!("{:?}", result.get_rows());
    Ok(())
}
```

`run_sql` submits SQL, waits for completion, and retrieves all result pages. It supports a performance option; `run_query` for saved queries does not.

## Run a saved query

For [query 971694](https://dune.com/queries/971694), the result columns are `symbol` and `max_price`:

```rust theme={null}
use duners::{DuneClient, DuneRequestError};
use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct PriceRow {
    symbol: String,
    max_price: f64,
}

#[tokio::main]
async fn main() -> Result<(), DuneRequestError> {
    let client = DuneClient::from_env();
    let result = client.run_query::<PriceRow>(971694, None, None).await?;
    println!("{:?}", result.get_rows());
    Ok(())
}
```

To use the query's `EnumParam` parameter, pass `Some(vec![duners::Parameter::list("EnumParam", "WETH")])` as the second argument to `run_query`.

For a previously executed query, use `client.get_latest_results::<PriceRow>(971694).await?` to fetch the latest existing JSON result without rerunning it. This call reads one result page. The SDK also provides `stream_query` and `stream_sql` for processing newly executed results page by page without buffering the entire dataset. See the [crate documentation](https://docs.rs/duners/latest/duners/) for query management and uploads.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.