{"id":13503075,"url":"https://github.com/fanzeyi/cargo-play","last_synced_at":"2025-04-12T15:37:02.756Z","repository":{"id":34892213,"uuid":"186214795","full_name":"fanzeyi/cargo-play","owner":"fanzeyi","description":"A local Rust playground","archived":false,"fork":false,"pushed_at":"2023-03-05T16:31:41.000Z","size":1999,"stargazers_count":345,"open_issues_count":19,"forks_count":19,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-03T15:11:12.114Z","etag":null,"topics":["cargo","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fanzeyi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-12T05:18:46.000Z","updated_at":"2025-02-16T20:56:15.000Z","dependencies_parsed_at":"2024-10-22T18:40:57.714Z","dependency_job_id":null,"html_url":"https://github.com/fanzeyi/cargo-play","commit_stats":{"total_commits":66,"total_committers":17,"mean_commits":"3.8823529411764706","dds":0.4242424242424242,"last_synced_commit":"146b6007b456fb87fac6b7c6d020329f9b480e9d"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanzeyi%2Fcargo-play","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanzeyi%2Fcargo-play/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanzeyi%2Fcargo-play/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanzeyi%2Fcargo-play/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fanzeyi","download_url":"https://codeload.github.com/fanzeyi/cargo-play/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248590469,"owners_count":21129826,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cargo","rust"],"created_at":"2024-07-31T22:02:35.896Z","updated_at":"2025-04-12T15:37:02.730Z","avatar_url":"https://github.com/fanzeyi.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# cargo-play\n\n[![Build Status](https://travis-ci.org/fanzeyi/cargo-play.svg?branch=master)](https://travis-ci.org/fanzeyi/cargo-play) [![Crates.io](https://img.shields.io/crates/v/cargo-play)](https://crates.io/crates/cargo-play)\n\n`cargo-play` is a tool to help you running your Rust code file without manually setting up a Cargo project.\n\n## See it in action\n\n\u003cimg src=\"https://raw.githubusercontent.com/fanzeyi/cargo-play/master/recordings/vim.gif\" width=\"600\"\u003e\n\n## Install\n\n```\ncargo install cargo-play\n```\n\n## Usage\n\nSimply running `cargo play \u003cfiles\u003e` is sufficient. You can specify your external dependency at the\nbeginning of your file with the prefix `//#`. It accepts the same TOML syntax as in `Cargo.toml`.\n\n## Example\n\n```rust\n$ cat serde_json.rs\n//# serde_json = \"*\"\n\nuse serde_json::{Result, Value};\n\nfn main() -\u003e Result\u003c()\u003e {\n    // Some JSON input data as a \u0026str. Maybe this comes from the user.\n    let data = r#\"\n        {\n            \"name\": \"John Doe\",\n            \"age\": 43,\n            \"phones\": [\n                \"+44 1234567\",\n                \"+44 2345678\"\n            ]\n        }\"#;\n\n    // Parse the string of data into serde_json::Value.\n    let v: Value = serde_json::from_str(data)?;\n\n    // Access parts of the data by indexing with square brackets.\n    println!(\"Please call {} at the number {}\", v[\"name\"], v[\"phones\"][0]);\n\n    Ok(())\n}\n\n$ cargo play serde_json.rs\n    Updating crates.io index\n   Compiling serde v1.0.91\n   Compiling ryu v0.2.8\n   Compiling itoa v0.4.4\n   Compiling serde_json v1.0.39\n   Compiling gvzcg8yviqmd_euq3xti4-zbkrs v0.1.0 (/var/folders/nq/608n9lcx02n_mzx33_3z5wyw0000gn/T/cargo-play.GVzCg8yviQmd_EUq3Xti4-ZbKRs)\n    Finished dev [unoptimized + debuginfo] target(s) in 10.23s\n     Running `/var/folders/nq/608n9lcx02n_mzx33_3z5wyw0000gn/T/cargo-play.GVzCg8yviQmd_EUq3Xti4-ZbKRs/target/debug/gvzcg8yviqmd_euq3xti4-zbkrs`\nPlease call \"John Doe\" at the number \"+44 1234567\"\n```\n\nIt also supports running multiple files at the same time:\n\n```rust\n$ cat tests/multi/entry.rs\nmod hello;\n\nfn main() {\n    println!(\"Hello {}\", hello::world());\n}\n$ cat tests/multi/hello.rs\npub fn world() -\u003e String {\n    \"World\".into()\n}\n$ cargo play tests/multi/*\n   Compiling qvsjdw04fxh5cgpdkdvg6ite_ak v0.1.0 (/var/folders/nq/608n9lcx02n_mzx33_3z5wyw0000gn/T/cargo-play.QVSJDw04FxH5CGpDkDvg6itE_ak)\n    Finished dev [unoptimized + debuginfo] target(s) in 0.30s\n     Running `/var/folders/nq/608n9lcx02n_mzx33_3z5wyw0000gn/T/cargo-play.QVSJDw04FxH5CGpDkDvg6itE_ak/target/debug/qvsjdw04fxh5cgpdkdvg6ite_ak`\nHello World\n```\n\nFiles under sub-directories will be copied and placed relatively to the first file. Try:\n\n    cargo play tests/subdirs/**/*.rs\n\n## To Do\n\n- [ ] Editor plugins\n  - [x] Vim\n  - [ ] VS Code\n- [x] Toolchain supports\n- [x] Edition Support\n\n## Editor Support\n\n### Vim\n\nAdd this line to your `.vimrc` or `init.vim`:\n\n```vim\ncommand! CargoPlay !cargo play %\n```\n\nWith your code file open, running `:CargoPlay` will allow you to test your current file within an auto-generated cargo project.\n\n### VSCode\n\nInstall the [VSCode Extension](./extension/README.md)\n\nOR\n\nOpen Command Palette and select **Configure Task**\n- *This will either create a new tasks.json or open your existing tasks.json*\n\nAdd the following [task](./.vscode/tasks.json):\n\n```json\n{\n    \"version\": \"2.0.0\",\n    \"tasks\": [\n        {\n            \"type\": \"shell\",\n            \"label\": \"CargoPlay\",\n            \"command\": \"cargo\",\n            \"args\": [\n                \"play\",\n                \"${file}\",\n            ],\n            \"problemMatcher\": [\n                \"$rustc\"\n            ]\n        }\n    ]\n}\n```\n\nNow open the Command Palette, select **Run Task** and then run the new **CargoPlay** task\n\n\u003cimg src=\"./recordings/vscode_run_task.png\" width=\"600\"\u003e\n\n### Micro\n\nadd this to your [micro](https://micro-editor.github.io/) `~/.config/micro/init.lua`\n\n```lua\nlocal config = import(\"micro/config\")\nlocal shell = import(\"micro/shell\")\n\nfunction init()\n    config.TryBindKey(\"Alt-b\", \"lua:initlua.play\", true)\n    config.MakeCommand(\"cargoplay\", play, config.NoComplete)\nend\n\nfunction play(bp)\n\n    bp:Save()\n\n    if bp.Buf:FileType() == \"rust\" then\n        shell.RunInteractiveShell(\"cargo play \" .. bp.Buf.Path, true, false)\n    end\nend\n\n```\n\nThen 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**\n\n\n## Acknowledgements\n\nThis project is inspired by [play.rust-lang.org](https://play.rust-lang.org) and [RustPlayground](https://github.com/cmyr/RustPlayground).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffanzeyi%2Fcargo-play","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffanzeyi%2Fcargo-play","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffanzeyi%2Fcargo-play/lists"}