Everyday Crates

These are domain-agnostic crates that I use in most projects, ordered from "everyone needs it" to "you probably need it".

There are a ton of great crates for lots of different purposes. Check out the awesome list for a list categorized by with specific domains.


wherror
It's thiserror, but with more features like falling back to enum variant names for error descriptions and automatic error location tracking.

error-stack
It's kind of like a cross between anyhow and map_err. You can use the question mark operator for any error types in a function and map it to the required error type, while also maintaining all inner errors on a stack (hence the name). This lets you specify a concrete error as a return type (great for traits) while still having access to all error information.
It also has ways to provide "hooks" which enable you to attach extra information to errors and then display it using custom formatting.

derive_more
Extra derives like From and Display. Also includes customizable Debug implementations.

smart-default
Customize the default values for each field with #[derive(SmartDefault)]

tracing
Generate traces

bon
Type-safe builders via #[derive(Builder)].
I use this a lot to make it easier to configure test doubles and just for setting up tests in general.

strum
"String Enum". Get an iterator over enum variants, convert strings to enums, convert enums to strings, etc.

num_enum
Safe conversion between numeric values and untagged enums

serde
Serializing and deserializing

paste
stringify!(), but it makes identifiers instead. For macro usage.

kanal
If you need a channel, use this.

parking_lot
If you need a mutex, use this.

itertools
A whole bunch of extra iterator adapters.

clap
Command Line Argument Parser. Go from a struct into a fully-feature CLI.

dotenvy
Load a .env file

regex
Regular expressions

tempfile
Create temporary files and directories. Great for testing.

toml
Parse/write TOML configuration

arc-swap
High-performance shared data for read-heavy workflows. Great for reading configuration values continuously while still being able to change them without lock overhead.

chrono
Time

tap
Adds .pipe(|v|) to everything allowing you to "pipe" data from one thing into another. Also adds .tap(|v|) to inspect values in the middle of a pipeline.

linkme
Compile-time plugins basically. It brings things together from all over the codebase into an iterator which you can then use to gain access to all the things.

rayon
Adds .par_iter() to automatically parallelize an iterator.

dashmap
Concurrent HashMap that works like a regular HashMap. No need for RwLock.

ahash
Fast hasher. Use it instead of the default hasher in HashMaps and HashSets. (Note: not a cryptographically secure hasher)
Comments