Make and use playgrounds locally.

Overview

cargo playground

Cargo playground opens a local playground in the editor of your choice.

Install

You can install it directly using cargo

$ cargo install --git https://github.com/Lutetium-Vanadium/cargo-playground

Or clone the project and then install

$ git clone https://github.com/Lutetium-Vanadium/cargo-playground
$ cd cargo-playground
$ cargo install --path .

cargo-playground on crates.io was already registered to someone else as a dummy project, and is not this project. Please install only using the above methods.

Usage

A few examples:

# Create a new playground
$ cargo playground new -n test-playground rand

# List existing playgrounds
$ cargo playground ls

# Open an existing playground
$ cargo playground open -e vim -a=-o2 test-playground

Environment variables

The following environment variables are used:

  • VISUAL: The editor in which to open the playground. It is required unless --editor is given

  • CARGO_PLAYGROUND_DIR: The path to the directory which is used for creating playgrounds. If not set, the temp directory is used. eg: in unix: /tmp/cargo-playground/

cargo playground new

This creates and opens a new playground.

It has the following options and flags:

 -g, --gui             Indicates the editor is a GUI based
 --no-w                Do not pass -w flag when opening GUI editor
 -n, --name <name>     The name of the playground. By default it is
                       generated from the current timestamp
 -e, --editor <editor> The editor to open the project in. By default it
                       is taken from the VISUAL env variable.
 -a, --args <args>...  Args to be given to be supplied to the editor.

It also takes a list of dependencies in the following formats:

  1. <dep-name> eg: "rand"
  2. <dep-name> = <dep-version> eg: "rand = 0.7"

    <dep-version> should not have quotes

cargo playground open

This opens a playground with the given name.

It has the following options and flags:

 -g, --gui             Indicates the editor is a GUI based
 --no-w                Do not pass -w flag when opening GUI editor
 -e, --editor <editor> The editor to open the project in. By default it
                       is taken from the VISUAL env variable.
 -a, --args <args>...  Args to be given to be supplied to the editor.

cargo playground ls

This lists all the playgrounds.

cargo playground clean

Deletes the Cargo projects in the playground directory.

It has the following options:

 -m, --matches <matches> A regex to match against playground names. If
                         not given all will be deleted.

Support

  • Terminal based editor + tmux: It opens a pane to the right which has the output process, and the editor will be open to the left. When the editor is closed, the playground will be closed.

  • GUI based editors: This requires the extra flag -g/--gui. It shows the output process in the main terminal and opens the editor.

    Any output from the editor to stdout/stdin will be ignored and not shown.

    For example:

    # Creates a new playground with vscode as editor
    $ cargo playground new -ge code
    #                        ^^^^^^-- not required if VISUAL is set to code
    

    I have noticed that cli openers for gui programs exit instantly and require a -w flag to make it wait. As such opening with gui editors automatically supplies a -w flag. In case your editor doesn't behave this way, use the --no-w flag to disable it.

If you want to add specific for some editor or environment feel free to open a PR!

Credits to Sergey Potalov and his post Rust Playground At Your Fingertips for the inspiration!

Comments
  • Playground commands in bash history

    Playground commands in bash history

    cd /tmp/cargo-playground/playground-1616203988 && /home/bart/.cargo/bin/cargo-playground watch playground-1616203988

    Not ideal: probably need to invoke the shell with different arguments.

    opened by BartMassey 6
  • Always just prints

    Always just prints "Hello, world!" on my box

    Running cargo playground with no arguments or with a crate-name argument merely prints "Hello, world!". Would be better to fail with a help message on unknown commands and when "--help" is supplied.

    opened by BartMassey 4
  • Playgrounds are kept in /tmp

    Playgrounds are kept in /tmp

    Keeping playgrounds in /tmp is a bit dangerous, as they may be removed at any time — especially after a reboot. Should probably be kept someplace more permanent, perhaps $HOME/.cache/cargo-playground or $HOME/.cargo-playground

    opened by BartMassey 3
  • differing help messages depending on invocation

    differing help messages depending on invocation

    Running cargo-playground --help yields

    cargo-playground 0.1.0
    Make and use playgrounds locally
    
    USAGE:
        cargo playground <SUBCOMMAND>
    
    FLAGS:
        -h, --help       Prints help information
        -V, --version    Prints version information
    
    SUBCOMMANDS:
        help          Prints this message or the help of the given subcommand(s)
        playground    Make and use playgrounds locally
        watch         Internal command required for running the playground --
                      good idea not to use it
    

    Running cargo playground --help yields

    cargo-playground 0.1.0
    Make and use playgrounds locally
    
    USAGE:
        cargo playground <SUBCOMMAND>
    
    FLAGS:
        -h, --help       Prints help information
        -V, --version    Prints version information
    
    SUBCOMMANDS:
        help    Prints this message or the help of the given subcommand(s)
        ls      List currently existing playgrounds
        new     Creates a new playground
        open    Opens an already existing playground
    

    I guess this is a consequence of how the thing is used by Cargo vs humans? Maybe not much can be done about it. Feel free to close, as I'm probably just confused.

    opened by BartMassey 1
  • Crate templates

    Crate templates

    This PR adds support for using examples as a template for a playground.

    However, there are a few issues:

    • Some libraries don't have a examples directory
    • Some libraries have an examples directory, but it is not included in the crate on crates.io (eg: rand 0.8)
    opened by Lutetium-Vanadium 0
  • CARGO_PLAYGROUND_DIR & clean

    CARGO_PLAYGROUND_DIR & clean

    Use CARGO_PLAYGROUND_DIR if set to determine where the playground is made. If not set, it will default to the temp directory.

    Also added a clean command, to delete all Cargo projects in a directory, optionally matching on some regex.

    Fixes #3

    opened by Lutetium-Vanadium 0
Owner
null
rust database for you to use and help me make!

Welcome To Rust Database! What is this? this is a database for you to git clone and use in your project! Why should i use it? It is fast and it takes

Carghai74 2 Dec 4, 2022
A simpler and 5x faster alternative to HashMap in Rust, which doesn't use hashing and doesn't use heap

At least 5x faster alternative of HashMap, for very small maps. It is also faster than FxHashMap, hashbrown, ArrayMap, and nohash-hasher. The smaller

Yegor Bugayenko 12 Apr 19, 2023
A tool to make grocery lists written in Rust

grusterylist: makes grocery lists, written in Rust grusterylist uses and can add to local libraries of user-added recipes and grocery items to put tog

null 3 Jun 17, 2022
Make a .scratch directory to keep random scribbles in

mkscratch Creates a directory named .scratch in your current working directory which will be ignored by Git. Useful for keeping around miscellaneous f

Kayla 3 Oct 21, 2022
A webring of people who make cool stuff. technology, music, art, writing, anything goes!

a webring of people who make cool stuff. technology, music, art, writing, anything goes!

Kognise 44 Dec 6, 2022
cargo-add command to make dependencies into dylibs

cargo add-dynamic This cargo command allows to wrap dependencies as dylibs. For why you might want this see Speeding up incremental Rust compilation w

Robert Krahn 62 Dec 27, 2022
Make your IDs strongly typed!!

About TypedId introduces a single type, aptly named TypedId. This is a generic wrapper any type, often types that you would use as an identifier. Howe

Tyler Bloom 8 Sep 2, 2022
A collection of crates to make minecraft development (client, server) with rust possible.

rust-craft rust-craft is a collection of crates to make minecraft development (client, server) with rust possible. Motivation There's no better way of

João Victor 15 Mar 23, 2023
A typed map which can make sure item exist.

Certain Map A typed map which can make sure item exist. What Problem Does It Solve In Rust, we often use Service abstraction for modular structure des

ihc童鞋@提不起劲 27 Jun 26, 2023
Aim is to make PCBoard clone that's finished on PCboards 100th birthday

icy_board Aim is to make PCBoard clone that's finished on PCboards 100th birthday - for sure it'll take much time. I've started to port a PPL decompil

Mike Krüger 6 May 7, 2024
Rust library for hardware accelerated drawing of 2D shapes, images, and text, with an easy to use API.

Speedy2D Hardware-accelerated drawing of shapes, images, and text, with an easy to use API. Speedy2D aims to be: The simplest Rust API for creating a

null 223 Dec 26, 2022
Simple and minimalist forward auth service intended for use with reverse proxies (Traefik, Caddy, nginx, etc)

nforwardauth nforwardauth is an extremely lightweight, blazing fast forward auth service that lets you use a single authentication middleware for all

Tony Duco 22 Apr 7, 2023
An attempt to start documenting the rust sdk for temporal and how to use it following some of the examples in typescript

This is an attempt to start documenting the rust sdk for temporal and how to use it following some of the examples in typescript.

Cosm 5 May 24, 2023
A tool to use docker / podman / oci containers with rust

contain-rs A tool to use docker / podman / oci containers with rust TODO improve error types improve error reporting handle std error for child proces

Felix Marezki 1 Jan 1, 2023
Small, clean, easy to use programming language

Thistle A modern, simplistic multi-paradigm language supporting object-oriented features Hello World! import IO object Main def main(): unit

null 7 Apr 13, 2022
A collection (eventually) of examples that use some non-beginner things.

nannou examples A collection (eventually) of examples that use some non-beginner things. Right now the only example combines nannou's standard draw AP

Alexis Andre 22 Oct 21, 2022
Demonstration of how to use the rust object_store crate

Introduction Demonstration of how to use the Rust object_store crate Example

Andrew Lamb 4 Aug 29, 2022
Game development practices with Rust programming language. I want to use different crates for this.

Hazır Oyun Motorlarını Kullanarak Rust Dili Yardımıyla Oyunlar Geliştirmek Rust programlama dilinde oyun geliştirmek için popüler birkaç hazır çatıyı

Burak Selim Senyurt 16 Dec 27, 2022
A dos attack for you to use!

Welcome To Rust Dos attacker! Why should I use it? It has unrivaled speeds because it is built in rust and hand optimized. It also comes with an AI mo

Carghai74 5 Dec 2, 2022