Officiële Rust SDK
Asynchrone crate met Tokio voor prestaties in Rust.
Asynchrone crate gericht op maximale prestaties met Tokio en Reqwest zonder overhead (zero-cost abstractions).
Installatie
TOML
[dependencies]smallpict = "1.2"tokio = { version = "1", features = ["full"] }Compleet toepassingsvoorbeeld
Rust
use smallpict::{Client, OptimizeOptions, Format};use std::fs;
#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> { let client = Client::new( std::env::var("SMALLPICT_API_KEY")?, std::env::var("SMALLPICT_SECRET_KEY")?, );
let bytes = fs::read("photo.jpg")?;
let res = client.optimize(&bytes, "photo.jpg", OptimizeOptions { format: Format::Avif, quality: 80, ..Default::default() }).await?;
println!("Geoptimaliseerde URL: {}", res.url); println!("Besparing: {:.2}%", res.savings_percentage);
Ok(())}