sdaas-rs 0.1.0

Official Rust SDK for SDaaS — Semantic Delta as a Service
Documentation
//! Basic example of using the SDaaS Rust SDK
//!
//! Demonstrates core delta computation functionality.
//!
//! Run with: `cargo run --example basic`

use sdaas_rs::Client;

fn main() {
    let rt = tokio::runtime::Runtime::new().unwrap();
    rt.block_on(main_async()).unwrap();
}

async fn main_async() -> Result<(), Box<dyn std::error::Error>> {
    println!("🚀 SDaaS Rust SDK - Basic Example\n");

    // Initialize client with your API key
    let client = Client::new(
        "your-api-key-here",
        "https://saas-core-production.up.railway.app",
    );

    // Example 1: Simple delta computation
    println!("📝 Example 1: Simple Delta Computation");
    println!("─────────────────────────────────────────\n");

    let source = "The quick brown fox";
    let target = "The fast brown fox";

    println!("Source: \"{}\"", source);
    println!("Target: \"{}\"\n", target);

    match client.compute_delta(source, target).await {
        Ok(response) => {
            println!("✅ Delta computed successfully!");
            println!("   📊 {} operations", response.delta.len());
            println!("   💾 {} bytes", response.size_bytes);
            println!(
                "   📈 {:.1}% compression\n",
                response.compression_ratio * 100.0
            );

            // Print delta operations
            println!("   Operations:");
            for (i, op) in response.delta.iter().enumerate() {
                match op {
                    sdaas_rs::DeltaOp::Insert { text } => {
                        println!("      {}: INSERT \"{}\"", i + 1, text);
                    }
                    sdaas_rs::DeltaOp::Delete { count } => {
                        println!("      {}: DELETE {} chars", i + 1, count);
                    }
                }
            }
        }
        Err(e) => {
            eprintln!("❌ Error: {}", e);
            return Err(Box::new(e) as Box<dyn std::error::Error>);
        }
    }

    // Example 2: Longer texts
    println!("\n📝 Example 2: Longer Texts");
    println!("─────────────────────────────────────────\n");

    let source2 = "The SDaaS platform provides semantic delta computation";
    let target2 = "The SDaaS platform offers powerful semantic delta computation services";

    println!("Source: \"{}\"", source2);
    println!("Target: \"{}\"\n", target2);

    match client.compute_delta(source2, target2).await {
        Ok(response) => {
            println!("✅ Delta computed!");
            println!("   📊 {} operations", response.delta.len());
            println!(
                "   📈 {:.1}% compression ratio",
                response.compression_ratio * 100.0
            );
        }
        Err(e) => {
            eprintln!("❌ Error: {}", e);
        }
    }

    println!("\n✅ Examples completed!");
    Ok(())
}