17 Rust’s most popular crates
This chapter covers
- The serde crate: convert between Rust types and formats like json
- The time module: basic functionality for time in the standard library
- The chrono crate: work with time and time zones
- The rayon crate: speed up your code with automatic threads for iterators
- The anyhow and thiserror crates: easily work with errors and error types
- The lazy static and oncecell crates: create statics that are initialized after the program starts
- Blanket trait implementations: automatically implement your traits on other types
This chapter is sort of a cookbook of some of the most popular external crates. These crates are so common that you can think of them as sort of extensions of the standard library - they’re not just random crates sitting around that nobody uses. Learning just these few crates crates will allow you to turn data like JSON into Rust structs, work with time and time zones, handle errors with less code, speed up your code, and work with global statics.
You’ll also learn about blanket trait implementations, which are extremely fun. With those you can give your trait methods to other people’s types even if they didn’t ask for them!
17.1 serde
The serde crate is an extremely popular one that lets you convert to and from formats like JSON, YAML, and so on. In fact, it's so popular that it's rare to find a Rust programmer who has never heard of it.