Rust Playground At Your Fingertips
source link: https://www.greyblake.com/blog/2021-03-12-rust-playground-at-your-fingertips/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Rust Playground At Your Fingertips
2021-03-12Coming to Rust from Ruby I miss the interactive console (IRB) lot.
Sometimes I go to Rust Plyaground online to test simple things,
but more often I go to /tmp
directory, create a new rust project, open Vim, run cargo watch -x run
and play.
It's very frequent scenario, why not automate it? This way I came to
a little shell script that relies on tmux
, cargo-watch
and nvim
.
#!/bin/sh PLAYGROUNDS_DIR="/tmp/rust-playgrounds" TIMESTAMP=$(date +"%Y%m%d%H%M%S") PROJECT_DIR="${PLAYGROUNDS_DIR}/playground${TIMESTAMP}" cargo new $PROJECT_DIR cd $PROJECT_DIR # Add dependencies to Cargo.toml for CRATE in $@; do sed "/^\[dependencies\]/a $CRATE = \"*\"" -i Cargo.toml done tmux new-session \; \ send-keys "nvim ./src/main.rs" C-m \; \ split-window -h \; \ send-keys "cargo watch -s 'clear && cargo run -q'" C-m \; \ select-pane -L;
I saved as playground
executable and put it into a directory with other binaries.
Now let's say I want to play with whatlang crate, then I just type:
playground whatlang
What I get is a project with whatlang
dependency in Cargo.toml
opened and running automatically.
I just need to type, save, and the result is shown immediately.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK