Rust SDK#

Async via tokio + reqwest. Builder-style configuration. Typed errors via thiserror.

Install#

cargo add rustbox-sdk tokio --features tokio/macros,tokio/rt-multi-thread

Quickstart#

use rustbox_sdk::{Rustbox, SubmitRequest};

#[tokio::main]
async fn main() -> Result<(), rustbox_sdk::RustboxError> {
    let client = Rustbox::new(&std::env::var("RUSTBOX_API_KEY").unwrap())?;

    let result = client.run(&SubmitRequest {
        language: "python".into(),
        code:     "print('hello')".into(),
        ..Default::default()
    }).await?;

    println!("{} {}", result["verdict"], result["stdout"]);  // AC hello
    Ok(())
}

run() submits, waits for sync completion, polls if needed, returns the verdict.

Errors#

use rustbox_sdk::RustboxError;

match client.run(&req).await {
    Ok(result) => { /* result["verdict"] */ }
    Err(RustboxError::Auth(_))    => { /* 401/403 - check API key */ }
    Err(RustboxError::RateLimit)  => { /* 429 - back off */ }
    Err(RustboxError::Server(_))  => { /* 5xx - SDK already retried */ }
    Err(RustboxError::Timeout)    => { /* exceeded timeout */ }
    Err(e)                        => { /* Transport, Decode, Api, ... */ }
}

Configuration#

let client = Rustbox::new(&api_key)?
    .with_base_url("https://rustbox.orkait.com")?  // default
    .with_timeout(std::time::Duration::from_secs(65))?  // default
    .with_max_retries(2);                              // default

Webhooks#

// Configure the webhook endpoint on the project in the dashboard first.
client.submit(&SubmitRequest {
    language: "python".into(),
    code: "...".into(),
    ..Default::default()
}, false, Default::default()).await?;

See Webhooks for HMAC verification.

Source#

github.com/orkait/rustbox-sdk/rust · docs.rs