Skip to content
smallPict
Start Free

Rust SDK

Official smallpict crate for asynchronous Rust applications.

The SmallPict Rust crate is built on tokio and reqwest.


Installation (Cargo.toml)

TOML
[dependencies]smallpict = "0.1.0"tokio = { version = "1", features = ["full"] }

Quickstart

Rust
use smallpict::{SmallPictClient, OptimizeOptions};use std::fs;
#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> {    let client = SmallPictClient::new(        std::env::var("SMALLPICT_API_KEY")?,        std::env::var("SMALLPICT_SECRET_KEY")?,    )?;
    let image_bytes = fs::read("hero.jpg")?;    let result = client.optimize(&image_bytes, OptimizeOptions::new().format("avif").quality(80)).await?;
    println!("Optimized URL: {}", result.url);    println!("Savings: {}%", result.savings_percentage);
    Ok(())}