# SDaaS Rust SDK (`sdaas-rs`)
[](https://crates.io/crates/sdaas-rs)
[](https://docs.rs/sdaas-rs)
[](LICENSE)
[](https://www.rust-lang.org/)
Official Rust SDK for **SDaaS** - Semantic Delta as a Service.
Compute powerful text deltas with semantic understanding, compression info, and enterprise-grade reliability.
## Features
- ✨ **Fully Async** - Built on `tokio` and `reqwest`
- 🔐 **Secure** - X-API-Key authentication with rustls-tls
- 📊 **Delta Computation** - Compute text diffs with compression metrics
- ✅ **Key Validation** - Check tier, quota, and rate limits in real-time
- 🛡️ **Type-Safe** - Full serde serialization with type safety
- 📚 **Well Documented** - Comprehensive examples and API docs
- 🚀 **Production Ready** - Battle-tested error handling
macros", "rt-multi-thread"] }
```
Or use `cargo add`:
```bash
cargo add sdaas-rs tokio
## Installation
Add to your `Cargo.toml`:
```toml
[dependencies]
sdaas-rs = "0.1"
tokio = { version = "1", features = ["full"] }
```
## Quick Start
### Compute Delta
```rust
use sdaas_rs::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new(
"your-api-key",
"https://saas-core-production.up.railway.app"
);compression: {:.1}%", delta.compression_ratio * 100.0);
for op in &delta.delta {
println!(" {:?}", op);
}
Ok(())
}
```
### Validate API Key
```rust
use sdaas_rs::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new(
"your-api-key",
"https://saas-core-production.up.railway.app"
);
let validation = client.validate_key().await?;
println!("🎯 Tier: {}", validation.key.tier);
println!("📊 Quota: {}/{}",
validation.key.quota_limit - validation.key.quota_remaining,
validation.key.quota_limit
);
Ok(())
}
```
## Running Examples
Try the included examples:
```bash
# Basic delta computation
cargo run --example basic
# API key validation
cargo run --example validation println!("Tier: {}", validation.key.tier);
println!("Quota limit: {}", validation.key.quota_limit);
println!("Quota remaining: {}", validation.key.quota_remaining);
println!("Rate limit: {}/second", validation.key.rate_limit);
Ok(())
}
```
## API Reference
### `Client`
#### Methods
- `new(api_key: &str, base_url: &str) -> Self` - Create new client
- `compute_delta(source: &str, target: &str) -> Result<DeltaResponse>` - Compute text delta
- `validate_key() -> Result<ValidationResponse>` - Validate API key and get quota info
- `set_api_key(api_key: &str)` - Update API key
- `base_url() -> &str` - Get current base URL
### `DeltaResponse`
```rust
pub struct DeltaResponse {
pub delta: Vec<DeltaOp>, // Operations to transform source to target
pub size_bytes: usize, // Size of delta in bytes
pub compression_ratio: f32, // Compression efficiency
}
```
### `DeltaOp`
```rust
pub enum DeltaOp {
Insert { text: String }, // Insert text at position
Delete { count: usize }, // Delete N characters
}
```
### `ValidationResponse`
```rust
pub struct ValidationResponse {
Handle errors gracefully with detailed error types:
```rust
use sdaas_rs::{Client, Error};
#[tokio::main]
async fn main() {
let client = Client::new("key", "https://saas-core-production.up.railway.app");
match client.compute_delta("a", "b").await {
Ok(delta) => println!("✅ Success!"),
Err(Error::Unauthorized) => eprintln!("❌ Invalid API key"),
Err(Error::RateLimitExceeded) => eprintln!("⏱️ Rate limited, retry later"),
Err(Error::QuotaExceeded) => eprintln!("💳 Quota exhausted"),
Err(e) => eprintln!("❌ Error: {}", e),
}
}
```
## API Reference
### Client Methods
- `new(api_key, base_url) -> Self` - Create new client
- `compute_delta(source, target) -> Result<DeltaResponse>` - Compute text delta
- `validate_key() -> Result<ValidationResponse>` - Validate and get quota info
- `set_api_key(api_key)` - Update API key
- `base_url() -> &str` - Get current base URL
### Response Types
```rust
// Delta computation result
pub struct DeltaResponse {
pub delta: Vec<DeltaOp>, // Insert/Delete operations
pub size_bytes: usize, // Compressed size
pub compression_ratio: f32, // 0.0-1.0 efficiency
}
// API key validation result
pub struct ValidationResponse {
pub valid: bool,
pub key: KeyValidation,
}
pub struct KeyValidation {
pub tier: String, // free/pro/enterprise
pub quota_limit: u64,
pub quota_remaining: u64,
pub rate_limit: u32, // req/second
pub rate_limit_remaining: u32,
}
```
## Error Types
```rust
pub enum Error {
Http(reqwest::Error), // Network errors
Unauthorized, // Invalid API key
RateLimitExceeded, // 429 Too Many Requests
QuotaExceeded, // 402 Payment Required
InvalidResponse(String), // Malformed response
InvalidApiKey, // Missing/invalid key
Api(String), // Other API errors
}
```
## Development
### Prerequisites
- Rust 1.70+
- Cargo
### Build & Test
```bash
# Build
cargo build
# Run tests
cargo test
# Check code
cargo fmt --check
cargo clippy
# Generate docs
cargo doc --open
```
## Contributing
We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
## License
Licensed under the MIT License - see [LICENSE](LICENSE) file for details.
## Getting Help
- 📖 [Documentation](https://docs.rs/sdaas-rs)
- 💬 [GitHub Issues](https://github.com/Jelco3d/saas-core/issues)
- 🌐 [Website](https://saas-core-production.up.railway.app)
## Related
- [Python SDK](https://github.com/Jelco3d/saas-core/.../sdaas-py)
- [API Documentation](https://saas-core-production.up.railway.app/docs)
println!("Operations: {}", delta.delta.len());
println!("Size: {} bytes", delta.size_bytes);
println!("Ratio: {:.2}%", delta.compression_ratio * 100.0);
Ok(())
}
```
## License
MIT
## Support
For issues and questions, visit the [GitHub repository](https://github.com/yourusername/sdaas-rs).