Rust SDK
メモリ安全で超高性能な非同期Rustアプリケーション向け公式 smallpict crate。
公式SmallPict Rust crateは、tokio と reqwest をベースに構築され、メモリ割り当てゼロのHMAC署名計算を実現しています。
インストール (Cargo.toml)
TOML
[dependencies]smallpict = "0.1.0"tokio = { version = "1", features = ["full"] }クイックスタート実装例
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!("最適化後URL: {}", result.url); println!("削減率: {}%", result.savings_percentage);
Ok(())}