Rust SDK
The Trunkate AI Rust SDK offers the absolute lowest-latency, zero-cost abstraction bindings targeting the reqwest and tokio asynchronous runtimes.
Installation
cargo add trunkate-aiUsage (Universal Budget)
Trunkate’s budget parameter uses a StringOrInt enum to support both absolute tokens and proactive percentage buffers.
use trunkate_ai::{Client, StringOrInt};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new(None);
let text = "Your very long context...";
// OPTION A: Fixed Token Budget (Integer)
let res = client.optimize(text, None, Some(StringOrInt::Int(500)), None).await?;
// OPTION B: Proactive Percentage Buffer (String)
let res2 = client.optimize(text, None, Some(StringOrInt::String("20%".to_string())), None).await?;
println!("Optimized: {}", res.text);
Ok(())
}Parameter Reference
| Parameter | Type | Required | Description |
|---|---|---|---|
text | String | Yes | The natural language prompt to optimize. |
task | Option<String> | No | Optional guidance for preservation ranking. |
budget | Option<StringOrInt> | No | Absolute tokens (Int(500)) or percentage (String("20%")). |
model | Option<String> | No | Target LLM (default: gpt-4o). |
Last updated on