Rust Projects
5 small projects to understand Rust core concepts.
# |
Project |
Description |
01 |
Hello Cargo |
A quick intro to Rust syntax. |
02 |
Guessing Game |
A hands-on introduction to the Rust language. |
03 |
Minigrep |
A simple version of the classic command line tool grep. |
04 |
Hello |
A multithreaded web server that says hello. |
05 |
Game of Life |
A zero-player game to learn how to use Rust, WebAssembly, and JavaScript together. |
1) Hello Cargo
A quick intro to Rust syntax.
See 01-hello-cargo folder
Features
- installing Rustup, Rust for Visual Studio Code and Even Better TOML.
- setting up a project with Cargo.
- printing and formatting strings.
- handling variables.
- discovering primitive types.
- playing with strings, tuples, arrays and vectors.
- rendering conditionals.
- using loops, functions and pointer references.
- creating custom data types with structs.
- defining enums.
- grabbing args from CLI.
Based on Rust Crash Course by Brad Traversy (2019).
2) Guessing Game
A hands-on introduction to the Rust language.
See 02-guessing-game folder
Features
- handling user input with the io library.
- adding rand from crates.io as a dependency.
- generating a secret number.
- comparing the guess to the secret number.
- allowing multiple guesses with looping.
- quitting after a correct guess.
- handling invalid input.
Based on The Rust Programming Language by Steve Klabnik and Carol Nichols (2021).
3) Minigrep
A simple version of the classic command line tool grep.
See 03-minigrep folder
Features
- accepting command line arguments.
- reading a file.
- refactoring to improve modularity and error handling.
- developing the librarys functionality with Test-Driven Development (TDD).
- working with environment variables.
- writing error messages to standard error instead of standard output.
- using closures and iterators.
Based on The Rust Programming Language by Steve Klabnik and Carol Nichols (2021).
4) Hello
A multithreaded web server that says hello.
See 04-hello folder
Features
- listening to the TCP connection and reading the request.
- writing a response and returning HTML.
- validating the request and selectively responding.
- simulating a slow request.
- improving throughput with a thread pool.
- handling graceful shutdown.
Based on The Rust Programming Language by Steve Klabnik and Carol Nichols (2021).
5) Game of Life
A zero-player game to learn how to use Rust, WebAssembly, and JavaScript together.
See 05-game-of-life folder
Features
- cloning the project template and understanding the folder structure.
- building the project with wasm-pack.
- putting it into a web page with wasm-app.
- serving locally with webpack.
- implementing the Game of Life with Rust.
- rendering to canvas directly from memory with JavaScript.
- testing the tick function and debugging.
- pausing and resuming the game.
- toggling a cell's state on click.
- optimizing performances with time profiling and benchmarking.
- shrinking .wasm size with wasm-opt and gzip.
Based on The Rust and WebAssembly Book by The Rust and WebAssembly Working Group (2021).