playground_api/
lib.rs

1//! playground-api: Rust Playground API Client
2//! ===========================================
3//!
4//! `playground-api` is a Rust crate designed to simplify interaction with the
5//! Rust Playground API. It provides both an asynchronous client by default and
6//! an optional blocking client when compiled with the `blocking` feature.
7//!
8//! ## Features
9//!
10//! - **Async client** (default): uses `reqwest::Client` under the hood to send
11//!   non-blocking HTTP requests.  
12//! - **Blocking client** (`blocking` feature): enables `reqwest::blocking::Client`
13//!   for environments where async is not desired or available.
14//! - **Poise support** (`poise-bot` feature): makes all enums derive the
15//!   `poise::ChoiceParameter` macro.
16//!
17//! ## Installation
18//!
19//! Add to your `Cargo.toml`:
20//!
21//! ```toml
22//! [dependencies]
23//! playground-api = "0.3.0"  # or latest
24//! ```
25//!
26//! To enable the blocking client as well:
27//!
28//! ```toml
29//! [dependencies]
30//! playground-api = { version = "0.3.0", features = ["blocking"] }
31//! ```
32//!
33//! ## Usage
34//!
35//! ### Async (default)
36//!
37//! ```rust
38//! use playground_api::{Client, ExecuteRequest, Channel, Mode, Edition, Error};
39//!
40//! #[tokio::main]
41//! async fn main() -> Result<(), Error> {
42//!     // Uses the official https://play.rust-lang.org/ by default
43//!     let client = Client::default();
44//!
45//!     let req = ExecuteRequest::new(
46//!         Channel::Stable,
47//!         Mode::Release,
48//!         Edition::Edition2021,
49//!         false,
50//!         false,
51//!         r#"println!("Hello, async world!");"#.into(),
52//!     );
53//!
54//!     let res = client.execute(&req).await?;
55//!     println!("{}", res.stdout);
56//!     Ok(())
57//! }
58//! ```
59//!
60//! ### Blocking (with `blocking` feature)
61//!
62//! ```rust
63//! use playground_api::{blocking::Client, ExecuteRequest, Channel, Mode, Edition, Error};
64//!
65//! fn main() -> Result<(), Error> {
66//!     // Compile your crate with `--features blocking`
67//!     let client = Client::default();
68//!
69//!     let req = ExecuteRequest::new(
70//!         Channel::Stable,
71//!         Mode::Release,
72//!         Edition::Edition2021,
73//!         false,
74//!         false,
75//!         r#"println!("Hello, blocking world!");"#.into(),
76//!     );
77//!
78//!     let res = client.execute(&req)?;
79//!     println!("{}", res.stdout);
80//!     Ok(())
81//! }
82//! ```
83//!
84//! ## License
85//!
86//! This project is licensed under the MIT License.
87
88#[cfg(feature = "blocking")]
89pub mod blocking;
90
91mod client;
92pub mod endpoints;
93mod error;
94
95pub use client::Client;
96pub use error::Error;