8 releases
new 0.1.10 | May 16, 2025 |
---|---|
0.1.9 | May 16, 2025 |
#409 in Asynchronous
317 downloads per month
16KB
317 lines
Playground API
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.
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.1.0" # 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 client with an url to the playground of your choice (here the official one)
let client = Client::new("https://play.rust-lang.org/");
// Create a new ExecuteRequest
let req = ExecuteRequest::new(
Channel::Stable,
Mode::Release,
Edition::Edition2024,
false,
false,
"println!(\"Hello, world!\")".to_string()
)
// send the ExecuteRequest to the playground server and receive the result
let res = client.execute(&req).await.unwrap();
Example Output
Example Output:
Hello, world!
Currently supported methods
The following methods are already supported
client.execute
client.compile // not fully done yet (don't expect it to work with every request)
client.format
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.
Dependencies
~5–20MB
~203K SLoC