Rust's missing development batteries
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md

README.md

stdx-dev – the missing development batteries of Rust

New to Rust development and don't know how to improve your development? stdx-dev has the best tools.

First, you're going to want to write Rust code using your favorite editor or IDE, whether that's emacs, vi or sublime text, Eclipse or IntelliJ, Atom or VSCode – or something else entirely. Most tools seem to coalesce around racer and the nascent RLS (Rust Language Server). See Are we IDE yet? for further information.

A Note About Nightly

Some tools require a nightly Rust compiler to work. This is usually not a problem, because it's easy enough to run different Rust versions side by side thanks to rustup, and most of those tools are only needed while developing software and either don't factor into or can easily be removed from the final build. Nevertheless, not everyone wants to maintain a nightly Rust version for tooling, so we'll mark the respective crates with a ⚠ nightly only label.

If you want to have a nightly version, and already have rustup, just type rustup install nightly into your console. To update to the newest version, use rustup update nightly.

With that out of the way, here are the goods:

feature crate
code style / correctness clippy
formatting rustfmt
random testing quickcheck
benchmarks bencher
profiling flame
dependency management cargo-edit
dependency management cargo-outdated
dependency author listing cargo-authors

Clippy

Crate | Repository | Docs | MPL-2.0 | ⚠ nightly only

More than 180 lints (at the time of this writing) catch bugs and unfortunate patterns and give helpful suggestions.

Install and run clippy with:

cargo +nightly install clippy # install clippy, add "-f" to upgrade existing
cargo +nightly clippy # runs clippy on the current project

This will likely give you a list of warnings and suggestions. While there remain some false positives (and negatives), the overall quality is quite good, and having worked extensively with clippy, I can attest that it sharpens the newcomer's intuition about what rustic code makes.

Many IDEs can use clippy within their workflow. Also there's an experimental rustfix tool to auto-apply some of the suggestions (Warning: Will eat your code).

RustFMT

Crate | Repository | Docs | MIT / Apache-2.0

This program will format your code according to some "default" style. It is highly configurable and will only occasionally eat your laundry.

Install with cargo install rustfmt (add -f to update an existing installation) and run with cargo fmt for a whole project or rustfmt <file> to format a single file. There are multiple modes of operation, e.g. output as diff. Check out the documentation for further assistance.

Quickcheck

Crate | Repository | Docs | MIT / Unlicense

This is a crate you can use to generate a series of random inputs for your tests and reduce the input in case of test failure.

If you have [cargo-edit], you can type cargo add --dev quickcheck into a command line in your crate root. Otherwise, add the following to your Cargo.toml manually:

[dev-dependencies]
quickcheck = "0.4"

Now you can use quickcheck in your tests! The easiest way is:

#[macro_use] extern crate quickcheck;

quickcheck! {
    // any predicate of any type that has an `Arbitrary` implementation
    // most default types already have one
    fn check_it(a: usize, b: usize) -> bool {
        a == b || a != b
    }
}

Bencher

Crate | Repository | Docs | MIT / Apache-2.0

Rust has an internal benchmarking tool, but it's only available on nightly behind a feature gate. This package makes benchmarks available on stable.

You'll need the following incantations in your Cargo.toml:

[dev-dependencies]
bencher = "0.1"

# and for each file:
[[bench]]
name = "bench_something"
harness = false

Now we can add src/bench_something.rs:

#[macro_use] extern crate bencher;

fn bench_mul(b: &mut bencher::Bencher) {
    let i = 1;
    b.iter(|| i * i);
}

// set up the benchmarks group
benchmark_group!(bench, bench_mul); // <- can add more benchmarks here
// and run it
benchmark_main!(bench);

This can be run with the usual cargo bench.

Flame

Crate | Repository | Docs | MIT / Apache-2.0

Flame is a library that allows you to stopwatch your code and see the result rendered as a flame graph. There is also the (⚠ nightly only) flamer plugin that lets you annotate your crates/modules/items to insert flame trace points.

Code augmented by flame can look like the following:

extern crate flame;

fn foo() {
   flame::start("foo");
   let result = ...;
   flame::end("foo");
   return result;
}

fn main() {
   flame::start("main");
   let foo = foo();
   ...
   flame::end("main");
}

The resulting flame graph can look like this:

https://raw.githubusercontent.com/TyOverby/flame/master/resources/screenshot.png

cargo-edit

Crate | Repository | Docs | MIT / Apache-2.0

This crate gives you the cargo add, cargo rm and cargo list subcommands, allowing for easy dependency management from the command line. Refer to the docs for further information.

cargo-outdated

Crate | Repository | Docs | MIT

This crate gives you the cargo outdated subcommand which displays when dependencies have newer versions available.

cargo-authors

Crate | Repository | Docs | MIT / Apache-2.0

This crate gives you the cargo authors subcommand which lists all the authors of all the dependencies of the crate in your current working directory.


About stdx-dev

The stdx curated list of crates has some great crates that you can build on, but it lacks all kinds of crates that make development with Rust even more awesome.

So I'm going to try and list them here. If you find any crate I've missed, file an issue or a PR. Thank you!

The contents of this repository are licensed under MIT / Apache-2.0, at your discretion.