# Rust SDK

> cargo add shopsavvy-sdk for async Rust access to ShopSavvy product details, current offers from every retailer and price history, with typed errors.

*Source: https://shopsavvy.com/data/documentation/sdk-rust* · Part of the [ShopSavvy Data API documentation](https://shopsavvy.com/data/documentation.md)

---

Our official Rust SDK provides memory-safe, high-performance access to the ShopSavvy Data API with full type safety.

- [View on GitHub](https://github.com/shopsavvy/sdk-rust)
- [Crates.io](https://crates.io/crates/shopsavvy-sdk)

## Installation

```toml
[dependencies]
shopsavvy-sdk = "1.0"
tokio = { version = "1.0", features = ["full"] }
```

## Quick Start

```rust
use shopsavvy_sdk::{Client, Result};

#[tokio::main]
async fn main() -> Result<()> {
    // Create a new client
    let client = Client::new("ss_live_your_api_key_here")?;

    // Get product details
    let product = client.get_product_details("012345678901").await?;
    println!("Product: {}", product.data.name);

    // Get current offers
    let offers = client.get_current_offers("012345678901", None).await?;
    for offer in offers.data {
        println!("{}: ${:.2}", offer.retailer, offer.price);
    }

    // Get price history
    let history = client.get_price_history(
        "012345678901",
        "2024-01-01",
        "2024-01-31",
        None
    ).await?;

    Ok(())
}
```

## Error Handling

```rust
use shopsavvy_sdk::{Client, Error};

match client.get_product_details("invalid-id").await {
    Ok(product) => println!("Found: {}", product.data.name),
    Err(Error::NotFound) => println!("Product not found"),
    Err(Error::RateLimit) => println!("Rate limit exceeded"),
    Err(Error::Authentication) => println!("Invalid API key"),
    Err(e) => println!("Other error: {}", e),
}
```

## Features

- Memory safe with zero-cost abstractions
- Full async/await support with tokio
- Strongly typed with serde serialization
- Comprehensive error handling
- Built-in rate limiting
- Support for Rust 1.70+
