
Node to Rust, Day 24: Crates & Valuable Tools
December 24, 2021
Introduction
Hopefully you’ve become comfortable enough with Rust that you want to continue your journey. Rust is hard to get into but it’s worth it. I’ve found that I can build massive projects with a fraction of the unit tests I’m used to writing. Rust handles so many error cases at the compilation stage. Writing Rust is like pair programming with a grumpy old developer who catches everything.
Now you need to start building up your suite of core dependencies, the crates you rely on repeatedly and become part of your personal toolbox. These are a few of the crates in mine.
Quick links
- Day 1: From nvm to rustup
- Day 2: From npm to cargo
- Day 3: Setting up VS Code
- Day 4: Hello World (and your first two WTFs)
- Day 5: Borrowing & Ownership
- Day 6: Strings, part 1
- Day 7: Syntax and Language, part 1
- Day 8: Language Part 2: From objects and classes to HashMaps and structs
- Day 9: Language Part 3: Class Methods for Rust Structs (+ enums!)
- Day 10: From Mixins to Traits
- Day 11: The Module System
- Day 12: Strings, Part 2
- Day 13: Results & Options
- Day 14: Managing Errors
- Day 15: Closures
- Day 16: Lifetimes, references, and
'static
- Day 17: Arrays, Loops, and Iterators
- Day 18: Async
- Day 19: Starting a large project
- Day 20: CLI Arguments & Logging
- Day 21: Building and Running WebAssembly
- Day 22: Using JSON
- Day 23: Cheating The Borrow Checker
- → Day 24: Crates & Tools
The code in this series can be found at wasmflow/node-to-rust
Crates
Data
- serde - Data serialization ecosystem.
- serde_json - JSON parsing and stringification.
- parking_lot - Better Rust
Mutex
andRwLock
. - once_cell - When you think you want global variables.
Error handling
Logging
- log - Logging facade that abstracts logging usage away from the logger implementation.
- env_logger - Easy console logging controlled by an environment variable.
- test-log - Get
env_logger
-style output in your tests without worrying about initializing a logger. - pretty-env-logger -
env_logger
, but prettier. - tracing - a drop-in replacement for
log
andenv_logger
with expanded capabilities and first-class async support.
CLI
Async/concurrency
- tokio - Async runtime.
- tokio-stream - Stream utilities for Tokio.
- async-trait - For when you try to make traits with async methods.
- crossbeam - bidirectional communication channels and more.
Web
- rocket - An HTTP server with a great developer experience.
- reqwest - an easy-to-use HTTP client.
- hyper - a fast and correct HTTP implementation.
Functionality you expected in the standard library
- rand - random number generator and related tools.
- regex - Regular expressions.
- base64 - Base64 implementation.
- http - A general purpose library of common HTTP types.
Misc & tools
- uuid - UUID implementation.
- itertools - Additional iterator functions and macros.
- maplit -
hashmap!{}
macro likevec![]
- cfg-if - Macros to simplify mutually exclusive conditional compilation
#[cfg]
attributes. just
- a bettermake
.
Additional reading
Wrap-up
During this series I learned that Rust has a curse. Once you learn “The Rust Way” of doing things, you get amnesia. You forget how to program any other way. This curse leads to documentation and examples that naturally skirt around problems 99% of new developers will experience in practice. I found myself unable to replicate several errors that were major roadblocks in my early Rust journey.
The Rust curse is why it’s critical that you are part of the Rust community. You are the only one that can help. You have a fresh perspective and run into real new-user problems. When you get stuck, reduce your code down to a minimally reproducible example and save it. When you eventually fix it, write about what you changed! If you don’t like writing, can’t figure something out, or are unsure about your fix, send it to me. I would be honored to take your experience and write about it.
Dont’ forget to join the our Discord channel to ask questions and share with others. Keep in touch! You can reach me personally at the email above or on twitter at @jsoverson.
Written By
