
If you're just getting started in Rust, you might wonder what kind of packages you should be exploring and how to get started in the community. Depending on your initial use case, here are a few resources I have found to be immensely helpful in learning rust. Enjoy!
The Definitive Book
Affectionately nicknamed “the book,” The Rust Programming Language will give you an overview of the language from first principles. You’ll build a few projects along the way, and by the end, you’ll have a solid grasp of the language.
https://doc.rust-lang.org/book/
All rustaceans need to make sure they read through this before they go anywhere else. It's the best guide there is on learning the language and it's practically everyone's starting point.
1. Crate:nom
nom is a parser combinators library written in Rust. Its goal is to provide tools to build safe parsers without compromising the speed or memory consumption. To that end, it uses extensively Rust's strong typing and memory safety to produce fast and correct parsers, and provides functions, macros and traits to abstract most of the error prone plumbing.
I was once trying to implement a simple netflow parser and I came acrossnom
. The ergonomics for implementing protocols is straightforward and it includes a number of helpful examples. Here's an example of a color parser!
externcratenom;usenom::{IResult,bytes::complete::{tag,take_while_m_n},combinator::map_res,sequence::tuple};#[derive(Debug,PartialEq)]pubstructColor{pubred:u8,pubgreen:u8,pubblue:u8,}fnfrom_hex(input:&str)->Result<u8,std::num::ParseIntError>{u8::from_str_radix(input,16)}fnis_hex_digit(c:char)->bool{c.is_digit(16)}fnhex_primary(input:&str)->IResult<&str,u8>{map_res(take_while_m_n(2,2,is_hex_digit),from_hex)(input)}fnhex_color(input:&str)->IResult<&str,Color>{let(input,_)=tag("#")(input)?;let(input,(red,green,blue))=tuple((hex_primary,hex_primary,hex_primary))(input)?;Ok((input,Color{red,green,blue}))}fnmain(){}#[test]fnparse_color(){assert_eq!(hex_color("#2F14DF"),Ok(("",Color{red:47,green:20,blue:223,})));}
In the repository you will find parsers for just about anything from programming languages, network protocols, misc formats like gameboy roms, and text formatting. Definitely worth looking at or keeping as a bookmark.
2. Crate:Bevy Game Engine
Bevy is an amazing game engine crate! It provides a number of fantastic out of the box tooling and features such as:
- Cross Platform: Windows, MacOS, and Linux (with planned support for mobile and web)
- 3D: Lights, meshes, textures, MSAA, and GLTF loading
- Sprites: Render individual images as sprites, render from sprite sheets, and dynamically generate new sprite sheets
- Assets: An extensible, event driven asset system that loads assets asynchronously in background threads
- Scenes: Save ECS Worlds to human-readable scene files and load scene files into ECS Worlds
- Plugins: All engine and app features are implemented as modular plugins
- Sound: Load audio files as assets and play them from within systems
- Multiple Render Backends: Vulkan, DirectX 12, and Metal (with more on the way thanks to wgpu)
- Data Driven Shaders: Easily bind ECS components directly to shader uniforms
- Hot Asset Reloading: Automatically reload changes to assets at runtime without recompiles or restarts
- Events: Efficiently consume and produce Events from within ECS systems
- Properties: Dynamically get and set component fields using a string version of their names
- Hierarchical Transforms: Create parent-child relationships between entities that propagate Transforms down the hierarchy
The design goals are to keep things very simple for newcomers while providing a lot of flexibility for seasoned developers. The ergonomics and compilation performance is really something to marvel at!
3. Crate:rocket.rs web framework
If you need to write a web site without sacrificing type safety, flexibility, and usability - then take a look at rocket.rs. I've tried using a number of different web frameworks from includingactix-web,tide, andwarp. There is much debate over the ecosystem here, but I think in the end I would have to putrocket.rs in this list.
#![feature(proc_macro_hygiene,decl_macro)]#[macro_use]externcraterocket;#[get("/hello/<name>/<age>")]fnhello(name:String,age:u8)->String{format!("Hello, {} year old named {}!",age,name)}fnmain(){rocket::ignite().mount("/",routes![hello]).launch();}
If you want a better overview and comparison between the different web frameworks and ergonomics check out this post byLuca Palmieri onChoosing a Rust Web Framework 2020 Edition.
4. Crate/Ecosystem:Tokio.rs
Tokio is an async runtime for the Rust programming language. There is some debate at the long termdifferences between the async-std but in any case, tokio is quite a powerhouse and you can't go very far without running into tokio dependencies in many rust crates.
Here is the starter for the mini redis tutorial:
usemini_redis::{client,Result};#[tokio::main]pubasyncfnmain()->Result<()>{// Open a connection to the mini-redis address.letmutclient=client::connect("127.0.0.1:6379").await?;// Set the key "hello" with value "world"client.set("hello","world".into()).await?;// Get key "hello"letresult=client.get("hello").await?;println!("got value from the server; result={:?}",result);Ok(())}
Check it out!
5. Crateserde serialization
Serde is a framework for serializing and deserializing Rust data structures into a variety of formats (complimented by things likeserde-json
useserde::{Deserialize,Serialize};useserde_json::Result;#[derive(Serialize,Deserialize)]structPerson{name:String,age:u8,phones:Vec<String>,}fntyped_example()->Result<()>{// Some JSON input data as a &str. Maybe this comes from the user.letdata=r#" { "name": "John Doe", "age": 43, "phones": [ "+44 1234567", "+44 2345678" ] }"#;// Parse the string of data into a Person object. This is exactly the// same function as the one that produced serde_json::Value above, but// now we are asking it for a Person as output.letp:Person=serde_json::from_str(data)?;// Do things just like with any other Rust data structure.println!("Please call {} at the number {}",p.name,p.phones[0]);Ok(())}
Here are a number ofgreat examples on their documentation website!
6. Crate:hyper HTTP
hyper is a fast HTTP implementation for Rust
- Aclient for talking to web services
- Aserver for building those web services
- Blazingfast thanks to Rust
- Highconcurrency with non-blocking sockets
- HTTP/1 and HTTP/2 support
usestd::{convert::Infallible,net::SocketAddr};usehyper::{Body,Request,Response,Server};usehyper::service::{make_service_fn,service_fn};asyncfnhandle(_:Request<Body>)->Result<Response<Body>,Infallible>{Ok(Response::new("Hello, World!".into()))}#[tokio::main]asyncfnmain(){letaddr=SocketAddr::from(([127,0,0,1],3000));letmake_svc=make_service_fn(|_conn|async{Ok::<_,Infallible>(service_fn(handle))});letserver=Server::bind(&addr).serve(make_svc);ifletErr(e)=server.await{eprintln!("server error: {}",e);}}
This helps if you want to get a bit more lower level than a "web framework" likewarp which builds on top of hyper.
7. Crate:textwrap
If you need a small quick library that knows how to wrap text for command line utilities, take a look at this crate.
[dependencies]textwrap = "0.12"
fnmain(){lettext="textwrap: a small library for wrapping text.";println!("{}",textwrap::fill(text,18));}
textwrap: a smalllibrary forwrapping text.
8. Crate:reqwest HTTP Client
If you need a more "batteries-included" HTTP request client then take a look at reqwest. Some of the includes features:
- Plain bodies, JSON, urlencoded, multipart
- Customizable redirect policy
- HTTP Proxies
- HTTPS via system-native TLS (or optionally, rustls)
- Cookie Store
- WASM
Here's an example below that usestokio.rs and the async runtime to do a simpleGET
request.
usestd::collections::HashMap;#[tokio::main]asyncfnmain()->Result<(),Box<dynstd::error::Error>>{letresp=reqwest::get("https://httpbin.org/ip").await?.json::<HashMap<String,String>>().await?;println!("{:#?}",resp);Ok(())}
9. Crate:cargo edit: cargo utility
There are a number of helpful utilities you can add to the built-incargo
command. The one I like to have iscargo-edit
which lets you do things like:
cargo add
$ # Add a specific version$ cargo add regex@0.1.41 --dev$ # Query the latest version from crates.io and adds it as build dependency$ cargo add gcc --build$ # Add a non-crates.io crate$ cargo add local_experiment --path=lib/trial-and-error/$ # Add a non-crates.io crate; the crate name will be found automatically$ cargo add lib/trial-and-error/$ # Add a crates.io crate with a local development path$ cargo add my_helper --vers=1.3.1 --path=lib/my-helper/$ # Add a renamed dependency$ cargo add thiserror --rename error
cargo rm
$ # Remove a dependency$ cargo rm regex$ # Remove a development dependency$ cargo rm regex --dev$ # Remove a build dependency$ cargo rm regex --build
cargo upgrade
# Upgrade all dependencies for the current crate$ cargo upgrade# Upgrade docopt (to ~0.9) and serde (to >=0.9,<2.0)$ cargo upgrade docopt@~0.9 serde@>=0.9,<2.0# Upgrade regex (to the latest version) across all crates in the workspace$ cargo upgrade regex --workspace
Super helpful when you don't want to editCargo.toml
10. Crate:cargo audit: cargo utility
Cargo-audit will auditCargo.lock
files for crates with security vulnerabilities reported to theRustSec Advisory Database. Very helpful!
Conclusion
These are only a small fraction of the vast Rust community out there. If you're looking to explore more, check out these helpfulAwesome Rust repositories for more!
- https://github.com/rust-unofficial/awesome-rust
- https://github.com/rust-embedded/awesome-embedded-rust
Cheers! 🍻
--
If you liked this article, please feel free to give me a follow and a like. Also check out mytwitter for more updates!
Thanks again!
Top comments(1)

- WorkSenior Java Developer at Open Web
- Joined
Awesome, giving a rust intro next week. Of course I'll point out they should read the book fist. And the whole tokio/hyper/warp/reqwest is pretty awesome. Might mention nom a d bevy, those are new to me.
For further actions, you may consider blocking this person and/orreporting abuse