#piston #execution-engine #code #api-bindings #emkc

piston_rs

An async wrapper for the Piston code execution engine

10 unstable releases (3 breaking)

0.4.3 Jun 30, 2022
0.4.2 Dec 31, 2021
0.3.0 Dec 9, 2021
0.2.3 Nov 30, 2021
0.1.0 Nov 27, 2021

#589 in Asynchronous

Download history 325/week @ 2024-02-19 16/week @ 2024-02-26 3/week @ 2024-03-04 9/week @ 2024-03-11 4/week @ 2024-03-18

334 downloads per month

MIT license

44KB
521 lines

piston_rs

Crate Docs Build

An async wrapper for the Piston code execution engine.

Why piston_rs

piston_rs aims to make interacting with Piston fun and easy. Your main tools are the Client and Executor structs.

The Executor is constructed containing the source code and other metadata about the code you are running. This is then sent to Piston via the Client.

piston_rs requires Rust version 1.46.0 or greater.

Getting started

For more details, check out the documentation!

Add piston_rs to your project

# Cargo.toml

[dependencies]
piston_rs = "^0.4"

Make requests to Piston

// main.rs

#[tokio::main]
async fn main() {
    let client = piston_rs::Client::new();
    let executor = piston_rs::Executor::new()
        .set_language("rust")
        .set_version("*")
        .add_file(
            piston_rs::File::default()
                .set_name("main.rs")
                .set_content("fn main() { println!(\"42\"); }")
        );

    match client.execute(&executor).await {
        Ok(response) => {
            println!("Language: {}", response.language);
            println!("Version: {}", response.version);

            if let Some(c) = response.compile {
                println!("Compilation: {}", c.output);
            }

            println!("Output: {}", response.run.output);
        }
        Err(e) => {
            println!("Something went wrong contacting Piston.");
            println!("{}", e);
        }
    }
}

License

piston_rs is licensed under the MIT License.

Dependencies

~4–18MB
~256K SLoC