playground-api 0.3.4

Simple API-binding for The Rust Playground
Documentation

Playground API

Crates.io Documentation Rust Version Downloads License Stars Forks

playground-api is a Rust crate designed to simplify interaction with the Rust Playground API. It provides an easy-to-use interface for executing Rust code snippets programmatically. It supports async and blocking Clients.

Features

  • Execute Rust code in the Rust Playground directly from your application.
  • Retrieve detailed output, including compilation errors or runtime results.
  • All while being rusty

Installation

Add the following to your Cargo.toml:

[dependencies]
playground-api = "0.2" # Replace with the latest version

Usage

To use the crate, first ensure you have an internet connection as it interacts with the Rust Playground API. Below is a simple example showcasing the .execute feature:

// Create a new ExecuteRequest with the default values
let req = ExecuteRequest::default();

// Create a new client with an url to the playground of your choice (here the official one)
let client = Client::new("https://play.rust-lang.org/");

// send the ExecuteRequest to the playground server and receive the result
let res = client.execute(&req).await.unwrap();

Example Output

Hello, world!

Supported methods

The following methods are supported

client.execute                  // Execute code
client.compile                  // Compile code to different targets
client.format                   // Format code using rustfmt
client.clippy                   // Use clippy on your code
client.miri                     // Run your code with the Miri interpreter
client.macro_expansion          // Expand your used macros
client.crates                   // Get the available crates
client.versions                 // Get the current rustc, rustfmt, clippy and miri versions
client.gist_create              // Create a new gist with your code
client.gist_get                 // Get a gist with an id

Documentation

For full documentation, including advanced usage and customization, visit docs.rs.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.