Learning Rust because I wanna get into low-level programming and do some cool stuff with it.
This technically follows the Rust Book coincidentally.
Projects on this repo:
- Hello World - Rust basics. (Like
node index.js) -rustc main.rs && ./main - Hello Cargo - Rust basics + Package Manager + Build Tool. (Like
npm run dev) - Guessing Game - Random number generate, then take user input until random number is guessed.
- Salary - Console app that estimates salary based on hourly, daily, monthly, and yearly rates.
- Tried Passwords CLI - Recreation of my Go implementation.
- HTTP Server - Simple HTTP server to understand networking and concurrency in Rust.
- Actix Server - API Server with a framework called Actix (Like Go's Fiber wrapped around HTTP standard libs).
- Rspc Server - API Server but typesafe for TypeScript (like tRPC), expect it's in Rust! Very sick. My fave, except redirects are not gonna be typesafe.
- Poem Server - API Server but easiest OAI integration so typesafe, Axum and Actix OAI integration is weird for me, here it's first class. Fixes my gripes with rspc, plus well maintained. But, you pretty much define redirects, streams, etc. Just standard web stuff.
- TCP Socket Chat - A console-based chat application using sockets to understand network communication.
- Random Quotes - A simple CLI application that fetches a random quote from the API Ninjas Quotes.
- Tic Tac Toe - A simple Tic Tac Toe game with persistence.
- WebSocket Chat - A console-based chat application using WebSockets to understand network communication on browser.
- Static Site Generator - Converts markdown to HTML.
- Tauri - Electron-like webview for Rust.
- GPUI_Hello - A simple
gpuiprogram (Zed's gui library) for practice. - GPUI_Input - A simple input field with
gpuifor practice. - Todo GUI Application - A simple GUI application to manage tasks.
- Install Rust using rustup - The installation and updating process is as convenient as Bun.
- CLI's you need to know:
rustupis for installing and updating Rust. Whilerustcis the compiler.cargois the package manager + build tool.- Coming from Bun, that's essentially:
bun,bun build, andbun install/bun run
- Coming from Bun, that's essentially:
cargo new <project-name>to create a new project in a file called project-name.cargo new --libto create a project with lib.rs crate.cargo initto create a project inside current folder.cargo buildto build the project orcargo runto build and run in one command. Orcargo build --releasefor a release build intarget/releaseinstead oftarget/debug.cargo run -qto run the program without the noise (doesn't remove the WARN though).cargo checkto see if it compiles or not.cargo updateupdates the dependencies (likepnpm update -iI think).cargo doc --openopens the docs of all your dependencies in the browser.cargo add <dep>add a cargo dep to the project. Or you can also add a snippet into[dependencies]ofCargo.tomlyourself.cargo install --path .Installs the binary to your path (It's not like bun install)- If you want something that "installs deps" like bun install, just run any:
cargo check,cargo build,cargo run, orcargo clippy --all-targets cargo install --listto see what you installed in your path.cargo clippy --all-targets- should be your primary feedback loop, can even do this on save.rustup component add rust-analyzer- if rust-analyzer has issues (LSP not starting).cargo clean -p <pkg>- wipes cached fingerprints for one package, forcing a full recompile next build (fixes. "edits not picked up" bugs, sometimes happens after I docargo publishand didcargo ragain but it's still outdated)
- Crate - module/package. Must have at least 1 crate. I think it's just either a
.rsfile or a "project". - Binary crate - inside
src/bin/*.rs- can have 0 or multiple. - Library crate - inside
src/lib.rs- can only have 1. mod- that's a module in code. By default it's private. Addpubto make it public.fnalso follows the same rule.structandimpl- Basically OOP in Rust, but better. Follows the same privacy rules asmodenum- you already know. Follows the same privacy rules asmodas well.
- Use
[profile.dev] opt-level = 1inCargo.tomlfor faster compile times before making release builds. - More:
# I got this from Bevy's docs.
# Enable a small amount of optimization in the dev profile.
[profile.dev]
opt-level = 1
# Enable a large amount of optimization in the dev profile for dependencies.
[profile.dev.package.'*']
opt-level = 3- Primary feedback loop instead of compile:
cargo clippy --all-targets. Can do this on save.
Libs that are kinda essential to know
- tokio - async (usually I do
cargo add tokio --features=rt-multi-threadfor most apps so async and#[tokio::main]works) - serde - for serializing/deserializing. It's very generic so treat it like a library.
- serde_json - specifically for JSON serialization/deserialization (not confused anymore ?)
- clap - for making CLIs
- bevy - making games
- wgpu - for programming the GPU (used by Firefox's web gpu)
- axum - for web apis and web framework stuff
- embassy - embedded systems
- rayon - for parallelism (contrasts with tokio for async)
- nom - for parsing, so you can avoid regex.
- cargo lambda - make rust bins for aws lambda easy
- wasm-bindgen - Rust program that can run in web (wasm). (I used this, very nice). + wasm-pack
- napi-rs - node.js add-ons in rust.
- polars - df library in rust (doesn't work in wasm). I use rowboat.
- Rust Book - Teaches Getting Started to Advanced Rust.
- Rust Book but Video Playlist by "Let's Get Rusty"
- Rustlings - Small exercises that can complement the Rust Book.
- Rust By Example - A collection of runnable examples that illustrate various Rust concepts and standard libraries.