百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

cargo-play

> 包管理
开源

一个本地 Rust 玩场

351 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

一个本地 Rust 玩场

cargo-play

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 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

…

It also supports running multiple files at the same time:

rust
$ 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
    • Vim
    • VS Code
  • Toolchain supports
  • Edition Support

Editor Support

Vim

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

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:

json
{
    "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

lua
local config = import("micro/config")
local shell = import("micro/shell")

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.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustcargorust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类包管理
定价开源

> 相关工具

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image