playground

Crates.ioplayground
lib.rsplayground
version0.1.0
sourcesrc
created_at2020-02-19 02:57:22.071185
updated_at2020-02-19 02:57:22.071185
descriptionRun Rust code without setting up Cargo
homepagehttps://github.com/SmiteWindows/playground
repository
max_upload_size
id210488
size39,742
Smite Rust (SmiteWindows)

documentation

README

playground

playground is a tool to help you running your Rust code file without manually setting up a Cargo project.

Install

cargo install playground

Usage

Simply running playground <files> is sufficient. You can specify your external dependency at the beginning of your file with the prefix //#. It accepts the same TOML syntax as in Cargo.toml.

Example

$ cat serde_json.rs
//# serde_json = "*"

use serde_json::{Result, Value};

fn main() -> Result<()> {
    // Some JSON input data as a &str. Maybe this comes from the user.
    let data = r#"
        {
            "name": "John Doe",
            "age": 43,
            "phones": [
                "+44 1234567",
                "+44 2345678"
            ]
        }"#;

    // Parse the string of data into serde_json::Value.
    let v: Value = serde_json::from_str(data)?;

    // Access parts of the data by indexing with square brackets.
    println!("Please call {} at the number {}", v["name"], v["phones"][0]);

    Ok(())
}

$ playground serde_json.rs

Please call "John Doe" at the number "+44 1234567"
Commit count: 0

cargo fmt