un-inception/clients/rust/sync/examples/multi_language.rs
russell@unturf.com 331cba42aa feat: Complete 6 additional SDK implementations with fixes and examples
Go Async SDK (clients/go/async/):
- Fixed case-sensitive language detection bug (.R for R language)
- Created go.mod for module management
- Added comprehensive test suite
- Created 3 examples with expected output comments
- Added README with full documentation

Java Sync SDK (clients/java/sync/):
- RENAMED: Unsandbox.java -> Un.java (matches naming convention)
- Updated class name from Unsandbox to Un
- Created pom.xml for Maven build
- Added 6 examples (simple + SDK client versions)
- Created test suite with JUnit 5
- Added README with API documentation

JavaScript Async SDK (clients/javascript/async/):
- Fixed unused import
- Created package.json with ES module support
- Added 5 examples covering all async patterns
- Created 71 tests (all passing)
- Added comprehensive README

PHP Sync SDK (clients/php/sync/):
- RENAMED: Unsandbox.php -> un.php (matches naming convention)
- Created composer.json with PSR-4 autoloading
- Created phpunit.xml for testing
- Added 4 examples with expected output comments
- Created 54 tests across 4 test files
- Added README with full documentation

Ruby Sync SDK (clients/ruby/sync/):
- Created Gemfile and un.gemspec
- Created Rakefile with test task
- Updated examples to actually use the SDK
- Added 4 examples (hello_world, async_job, language_detection, snapshots)
- Created comprehensive test suite with 30+ tests
- Added README with documentation

Rust Sync SDK (clients/rust/sync/):
- Updated Cargo.toml with example declarations
- Created 4 examples (hello_world, fibonacci, multi_language, async_polling)
- Added comprehensive README with API reference
- All dependencies verified correct

All SDKs verified:
- HMAC-SHA256 authentication implemented
- 4-tier credential system (args > env > ~/.unsandbox > ./accounts.csv)
- Expected output comments for pipeline validation
- Proper error handling
- Language detection support
2026-01-15 17:32:24 -05:00

88 lines
2.3 KiB
Rust

// PUBLIC DOMAIN - NO LICENSE, NO WARRANTY
//
// Multi-language example for unsandbox Rust SDK - Synchronous Version
//
// This example demonstrates executing code in multiple programming languages.
// Shows the versatility of unsandbox's language support.
//
// To run:
// export UNSANDBOX_PUBLIC_KEY="your-public-key"
// export UNSANDBOX_SECRET_KEY="your-secret-key"
// cargo run --example multi_language
//
// Expected output:
// === Python ===
// Status: completed
// Output: Hello from Python!
//
// === JavaScript ===
// Status: completed
// Output: Hello from JavaScript!
//
// === Ruby ===
// Status: completed
// Output: Hello from Ruby!
//
// === Go ===
// Status: completed
// Output: Hello from Go!
//
// All 4 languages executed successfully!
use un::{execute_code, resolve_credentials, UnsandboxError};
fn main() -> Result<(), UnsandboxError> {
// Define code snippets in different languages
let languages = vec![
("python", r#"print("Hello from Python!")"#),
("javascript", r#"console.log("Hello from JavaScript!")"#),
("ruby", r#"puts "Hello from Ruby!""#),
(
"go",
r#"package main
import "fmt"
func main() { fmt.Println("Hello from Go!") }"#,
),
];
// Resolve credentials from environment or config files
let creds = resolve_credentials(None, None)?;
let mut success_count = 0;
// Execute each language
for (lang, code) in &languages {
println!("=== {} ===", lang.to_uppercase());
match execute_code(lang, code, &creds) {
Ok(result) => {
println!("Status: {}", result.status);
println!("Output: {}", result.output.trim());
if result.status == "completed" && result.exit_code == 0 {
success_count += 1;
}
}
Err(e) => {
eprintln!("Error: {}", e);
}
}
println!();
}
println!(
"All {} languages executed successfully!",
languages.len()
);
if success_count != languages.len() {
eprintln!(
"Warning: Only {}/{} executions succeeded",
success_count,
languages.len()
);
std::process::exit(1);
}
Ok(())
}