Runner: a Rust snippet runner


#1

runner was inspired by a post here where someone declared themselves ‘disappointed’ in Cargo because it was awkward to use for testing out little bits of code. The post seems to have disappeared, probably out of embarrassment, but it struck me that a utility to run snippets that could be linked against external crates would be useful. A
’snippet’ is pretty much the same as a doc example - println!("Hello, World!") is a valid snippet. runner --create 'time json regex' will create a static cache containing theose crates, which any extern crate in snippets will link against.

There’s also a few Perl-inspired features, thanks to some useful comments on /r/reddit.

$ runner -e 'PathBuf::from("bonzo.dog").extension()'
Some("dog")

and some Rust-specific, like evaluating iterators:

$ runner -i '(0..5).map(|i| (10*i,100*i))'
(0, 0)
(10, 100)
(20, 200)
(30, 300)
(40, 400)

It’s installable with cargo, and any comments or suggestions are welcome.


#2

I really like the idea and how you’ve implemented this! Usually what I’ll do is cd into my /tmp/ directory, create a new executable with cargo new --bin foo, then add dependencies with something like cargo add error-chain serde.

This gets pretty annoying and repetitive when you just want to try something out on your local machine so I’ll definitely have to try out runner to see how it compares with my current workflow.


#3

I wanted to automate something that I do often, and save time when doing ad-hoc builds. Keeping a cache makes the whole thing much faster to setup, although of course you have to know when to say runner --build to update the cache. When possible, it does dynamic-linking since it does make a significant difference to the total build time. When building crates (with --compile) I’ve seen a build time of 2.3s cut in half.

This suits my slightly impatient nature.