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,ignore
38//! use playground_api::{Client, endpoints::{ExecuteRequest, Channel, Mode, Edition, CrateType}, 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//!         CrateType::Binary,
50//!         false,
51//!         false,
52//!         r#"println!("Hello, async world!");"#.into(),
53//!     );
54//!
55//!     let res = client.execute(&req).await?;
56//!     println!("{}", res.stdout);
57//!     Ok(())
58//! }
59//! ```
60//!
61//! ### Blocking (with `blocking` feature)
62//!
63//! ```rust,ignore
64//! use playground_api::{blocking::Client, endpoints::{ExecuteRequest, Channel, Mode, Edition, CrateType}, Error};
65//!
66//! fn main() -> Result<(), Error> {
67//!     // Compile your crate with `--features blocking`
68//!     let client = Client::default();
69//!
70//!     let req = ExecuteRequest::new(
71//!         Channel::Stable,
72//!         Mode::Release,
73//!         Edition::Edition2021,
74//!         CrateType::Binary,
75//!         false,
76//!         false,
77//!         r#"println!("Hello, blocking world!");"#.into(),
78//!     );
79//!
80//!     let res = client.execute(&req)?;
81//!     println!("{}", res.stdout);
82//!     Ok(())
83//! }
84//! ```
85//!
86//! ## License
87//!
88//! This project is licensed under the MIT License.
89
90#[cfg(feature = "blocking")]
91pub mod blocking;
92
93mod client;
94pub mod endpoints;
95mod error;
96
97pub use client::Client;
98pub use error::Error;