Skip to content

Instantly share code, notes, and snippets.

@curlpipe
Created March 20, 2021 20:36
Show Gist options
  • Save curlpipe/7129dab496adacc4ec45c175a86d9946 to your computer and use it in GitHub Desktop.
Save curlpipe/7129dab496adacc4ec45c175a86d9946 to your computer and use it in GitHub Desktop.
List of handy crates for Rust

A list of handy Rust crates

Here is a list of crates that will make your code and general Rust experience more readable and clean, because Rust can get pretty ugly sometimes.

I encourage you to check through each item in this list to determine if it is of some use to you.

Cargo

cargo-bloat

https://lib.rs/crates/cargo-bloat

Find out what takes most of the space in your executable.

This is useful if you have a large program with a large binary and want to reduce the size by inspecting which libraries and code takes up the most space.

cargo-limit

https://lib.rs/crates/cargo-limit

Cargo with less noise: warnings are skipped until errors are fixed, etc...

The output of cargo can be quite overwhelming to say the least. I've had many times where it's spat out hundreds of errors and warnings that I've had to scroll through, with duplicates. You can use this crate to limit the number of errors and warnings, give errors the highest priority, reverse all the errors to prevent scrolling and purging duplicate error messages amongst other things.

cargo-edit

https://lib.rs/crates/cargo-edit

This extends cargo to allow you to add and remove dependencies quickly.

I don't know about you, but when I want to add a dependency to my project, having to open up the Cargo.toml and type out everything with the correct version is painful. This crate will allow you to use commands like cargo add [dependency] and cargo rm [dependency] to very quickly modify your Cargo.toml to add and remove dependencies.

cargo-tarpaulin

https://lib.rs/crates/cargo-tarpaulin

Cargo-tarpaulin is a tool to determine code coverage achieved via tests.

When I write tests in Rust, it's hard to know if i've covered all bases. Tarpaulin is a tool that I use to ensure that most of my code is covered and that I haven't left anything out.

cargo-spellcheck

https://lib.rs/crates/cargo-spellcheck

Checks all doc comments for spelling mistakes.

Spelling mistakes are easy to make, this crate will make sure that what you have no spelling mistakes and allows you to very quickly rectify them.

cargo-aur

https://lib.rs/crates/cargo-aur

Prepare Rust projects to be released on the Arch Linux User Repository.

Adding a package to the AUR can be a bit confusing, especially if you don't use Arch Linux yet you have users that do. This allows cargo to very quickly generate PKGBUILD files ready for the AUR.

cargo-deb

https://lib.rs/crates/cargo-deb

Make Debian packages easily with a Cargo subcommand.

This is an easy way to package your Rust project for Debian, Ubuntu, Mint and other Debian based Linux distros.

cargo-watch

https://lib.rs/crates/cargo-watch

Watches over your Rust project's source.

This will monitor your source code for any changes and allow you to run cargo subcommands when they occur.

cargo-outdated

https://lib.rs/crates/cargo-outdated

Cargo subcommand for displaying when dependencies are out of date.

It will alert you as to when the dependencies in your project have an update. This is great if you always forget to update your dependencies.

cargo-readme

https://lib.rs/crates/cargo-readme

A cargo subcommand to generate a README.md contents from doc comments.

Writing a README can take some time. This subcommand will allow you to quickly generate a README file which you can edit further or use as-is.

Code

if_chain

https://lib.rs/crates/if_chain

Macro for writing nested if let expressions.

Rust is prone to indent-hell. It is quite common for you to have data that is wrapped in multiple Option and Result enums, requiring either several unwrap calls, which makes the code unsafe or using nested if and if let statements. This crate is a really neat way of avoiding that ugly code.

sugars

https://lib.rs/crates/sugars

A useful collection of macros to make tasks easier.

If you've ever tried initialisnig a HashMap with data in it or trying to wait a certain amount of time or benchmarking code with Rust, you'll know that it's a traumatic experience that makes code look verbose and ugly. Sugars is a crate that uses macros that allow you to skip over ugly Rust syntax for creating, modifying and managing data. It will allow you to create data structures, avoid ugly iterator function chains, providing sleep, duration and benchmark how long expressions take to execute (e.g. function calling). This is such a useful crate that really makes writing Rust so much less traumatic.

thiserror

https://lib.rs/crates/thiserror

Convenient derive macro for the standard library's Error trait.

Rust errors are super powerful but sometimes you can get confused with the many different types of errors in the standard library and perhaps you want make your own errors too. Doing this in pure Rust can get ugly and verbose very quickly. This crate is an extremely easy way of creating very powerful custom error types that will really make Rust shine.

cmd_lib

https://lib.rs/crates/cmd_lib

Rust command line macros and utilities to write shell script tasks easily.

If you've ever tried to run a command and get the output back, then you know how annoying it can be. This crate takes in shell commands and can support pipes, redirection and arguments with ease.

lazy_static

https://lib.rs/crates/lazy_static

A macro for declaring lazily evaluated statics in Rust.

If you have code that you want to be executed at runtime, this crate is a godsend. It can be used for things like initialising regex, populating vectors or hashmaps and anything that requires non-const functions. This is a way to speed up code quite a bit, it allows heavy tasks to be done at compile time, removing the time taken during runtime.

rayon

https://lib.rs/crates/rayon

Simple work-stealing parallelism for Rust.

Concurrency can get complicated fast. This crate provides a drop in replacement for iterators that process the contents in concurrently.

fs_extra

https://lib.rs/crates/fs_extra

A Rust library that provides additional functionality that isn't present in std::fs.

This crate allows you to copy files, recursively copy and move directories and files, easily writing and reading a string to and from a file, getting the size of a folder and a collection of directory entries. Useful if your project does a lot of file manipulation.

lazy-regex

https://lib.rs/crates/lazy-regex

A macro to reduce regex creation boilerplate.

Using regex in Rust can get pretty confusing and verbose. This crate is an extremely clean and efficient way to use regex, through a single macro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment