All Projects → fanzeyi → Cargo Play

fanzeyi / Cargo Play

Licence: mit
A local Rust playground

Programming Languages

rust
11053 projects

Labels

Projects that are alternatives of or similar to Cargo Play

Crate2nix
nix build file generator for rust crates
Stars: ✭ 123 (-34.92%)
Mutual labels:  cargo
Ocean
A C/C++ build system/project manager written in Rust
Stars: ✭ 144 (-23.81%)
Mutual labels:  cargo
Semantic Rs
🚀 Automatic crate publishing done right
Stars: ✭ 162 (-14.29%)
Mutual labels:  cargo
Thermite
A Rake-based helper for building and distributing Rust-based Ruby extensions
Stars: ✭ 125 (-33.86%)
Mutual labels:  cargo
Cargo Husky
Setup Git hooks automatically for cargo projects with 🐶
Stars: ✭ 141 (-25.4%)
Mutual labels:  cargo
Cargo About
📜 Cargo plugin to generate list of all licenses for a crate 🦀
Stars: ✭ 148 (-21.69%)
Mutual labels:  cargo
Meta Rust
OpenEmbedded/Yocto layer for Rust and Cargo
Stars: ✭ 108 (-42.86%)
Mutual labels:  cargo
Meuse
A private Cargo crate registry, for Rust
Stars: ✭ 173 (-8.47%)
Mutual labels:  cargo
Cargo Ndk
Compile Rust projects against the Android NDK without hassle
Stars: ✭ 141 (-25.4%)
Mutual labels:  cargo
Newrustacean.com
The official website for the New Rustacean podcast
Stars: ✭ 161 (-14.81%)
Mutual labels:  cargo
Stegbrute
Fast Steganography bruteforce tool written in Rust useful for CTF's
Stars: ✭ 134 (-29.1%)
Mutual labels:  cargo
Cargo Edit
A utility for managing cargo dependencies from the command line.
Stars: ✭ 2,095 (+1008.47%)
Mutual labels:  cargo
Cross
“Zero setup” cross compilation and “cross testing” of Rust crates
Stars: ✭ 2,461 (+1202.12%)
Mutual labels:  cargo
Kernel Roulette
A kernel module written in Rust
Stars: ✭ 124 (-34.39%)
Mutual labels:  cargo
Cargo Deps
Cargo subcommand for building dependency graphs of Rust projects
Stars: ✭ 168 (-11.11%)
Mutual labels:  cargo
Shadow Rs
A build-time information stored in your rust project.(binary,lib,cdylib,dylib)
Stars: ✭ 117 (-38.1%)
Mutual labels:  cargo
Core Os Riscv
🖥️ An xv6-like operating system on RISC-V with multi-core support. Documentation available online.
Stars: ✭ 144 (-23.81%)
Mutual labels:  cargo
Cargo Spellcheck
Checks all your documentation for spelling and grammar mistakes with hunspell and a nlprule based checker for grammar
Stars: ✭ 183 (-3.17%)
Mutual labels:  cargo
Routerify
A lightweight, idiomatic, composable and modular router implementation with middleware support for the Rust HTTP library hyper.rs
Stars: ✭ 173 (-8.47%)
Mutual labels:  cargo
Clippy Check
📎 GitHub Action for PR annotations with clippy warnings
Stars: ✭ 159 (-15.87%)
Mutual labels:  cargo

cargo-play

Build Status Crates.io

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

See it in action

Install

cargo install cargo-play

Usage

Simply running cargo play <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(())
}

$ cargo play serde_json.rs
    Updating crates.io index
   Compiling serde v1.0.91
   Compiling ryu v0.2.8
   Compiling itoa v0.4.4
   Compiling serde_json v1.0.39
   Compiling gvzcg8yviqmd_euq3xti4-zbkrs v0.1.0 (/var/folders/nq/608n9lcx02n_mzx33_3z5wyw0000gn/T/cargo-play.GVzCg8yviQmd_EUq3Xti4-ZbKRs)
    Finished dev [unoptimized + debuginfo] target(s) in 10.23s
     Running `/var/folders/nq/608n9lcx02n_mzx33_3z5wyw0000gn/T/cargo-play.GVzCg8yviQmd_EUq3Xti4-ZbKRs/target/debug/gvzcg8yviqmd_euq3xti4-zbkrs`
Please call "John Doe" at the number "+44 1234567"

It also supports running multiple files at the same time:

$ cat tests/multi/entry.rs
mod hello;

fn main() {
    println!("Hello {}", hello::world());
}
$ cat tests/multi/hello.rs
pub fn world() -> String {
    "World".into()
}
$ cargo play tests/multi/*
   Compiling qvsjdw04fxh5cgpdkdvg6ite_ak v0.1.0 (/var/folders/nq/608n9lcx02n_mzx33_3z5wyw0000gn/T/cargo-play.QVSJDw04FxH5CGpDkDvg6itE_ak)
    Finished dev [unoptimized + debuginfo] target(s) in 0.30s
     Running `/var/folders/nq/608n9lcx02n_mzx33_3z5wyw0000gn/T/cargo-play.QVSJDw04FxH5CGpDkDvg6itE_ak/target/debug/qvsjdw04fxh5cgpdkdvg6ite_ak`
Hello World

Files under sub-directories will be copied and placed relatively to the first file. Try:

cargo play tests/subdirs/**/*.rs

To Do

  • [ ] Editor plugins
    • [x] Vim
    • [ ] VS Code
  • [x] Toolchain supports
  • [x] Edition Support

Editor Support

Vim

Add this line to your .vimrc or init.vim:

command! CargoPlay !cargo play %

With your code file open, running :CargoPlay will allow you to test your current file within an auto-generated cargo project.

VSCode

Install the VSCode Extension

OR

Open Command Palette and select Configure Task

  • This will either create a new tasks.json or open your existing tasks.json

Add the following task:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "CargoPlay",
            "command": "cargo",
            "args": [
                "play",
                "${file}",
            ],
            "problemMatcher": [
                "$rustc"
            ]
        }
    ]
}

Now open the Command Palette, select Run Task and then run the new CargoPlay task

Micro

add this to your micro ~/.config/micro/init.lua

local config = import("micro/config")

function init()
    config.TryBindKey("Alt-b", "lua:initlua.play", true)
    config.MakeCommand("cargoplay", play, config.NoComplete)
end

function play(bp)

    bp:Save()

    if bp.Buf:FileType() == "rust" then
        shell.RunInteractiveShell("cargo play " .. bp.Buf.Path, true, false)
    end
end

Then you can hit Alt + b to build your current file usig cargo play or you can use Ctrl + E and in the command console type cargoplay

Acknowledgements

This project is inspired by play.rust-lang.org and RustPlayground.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].