Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦀 Rust Practice

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:

  1. Hello World - Rust basics. (Like node index.js) - rustc main.rs && ./main
  2. Hello Cargo - Rust basics + Package Manager + Build Tool. (Like npm run dev)
  3. Guessing Game - Random number generate, then take user input until random number is guessed.
  4. Salary - Console app that estimates salary based on hourly, daily, monthly, and yearly rates.
  5. Tried Passwords CLI - Recreation of my Go implementation.
  6. HTTP Server - Simple HTTP server to understand networking and concurrency in Rust.
  7. Actix Server - API Server with a framework called Actix (Like Go's Fiber wrapped around HTTP standard libs).
  8. 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.
  9. 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.
  10. TCP Socket Chat - A console-based chat application using sockets to understand network communication.
  11. Random Quotes - A simple CLI application that fetches a random quote from the API Ninjas Quotes.
  12. Tic Tac Toe - A simple Tic Tac Toe game with persistence.
  13. WebSocket Chat - A console-based chat application using WebSockets to understand network communication on browser.
  14. Static Site Generator - Converts markdown to HTML.
  15. Tauri - Electron-like webview for Rust.
  16. GPUI_Hello - A simple gpui program (Zed's gui library) for practice.
  17. GPUI_Input - A simple input field with gpui for practice.
  18. Todo GUI Application - A simple GUI application to manage tasks.

Notes

  • Install Rust using rustup - The installation and updating process is as convenient as Bun.
  • CLI's you need to know: rustup is for installing and updating Rust. While rustc is the compiler. cargo is the package manager + build tool.
    • Coming from Bun, that's essentially: bun, bun build, and bun install/bun run
  • cargo new <project-name> to create a new project in a file called project-name.
  • cargo new --lib to create a project with lib.rs crate.
  • cargo init to create a project inside current folder.
  • cargo build to build the project or cargo run to build and run in one command. Or cargo build --release for a release build in target/release instead of target/debug.
  • cargo run -q to run the program without the noise (doesn't remove the WARN though).
  • cargo check to see if it compiles or not.
  • cargo update updates the dependencies (like pnpm update -i I think).
  • cargo doc --open opens 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] of Cargo.toml yourself.
  • 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, or cargo clippy --all-targets
  • cargo install --list to 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 do cargo publish and did cargo r again but it's still outdated)

Terminologies

  • Crate - module/package. Must have at least 1 crate. I think it's just either a .rs file 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. Add pub to make it public. fn also follows the same rule.
  • struct and impl - Basically OOP in Rust, but better. Follows the same privacy rules as mod
  • enum - you already know. Follows the same privacy rules as mod as well.

Faster Rust feedback loop tips:

  • Use [profile.dev] opt-level = 1 in Cargo.toml for 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.

Libraries

Libs that are kinda essential to know

  • tokio - async (usually I do cargo add tokio --features=rt-multi-thread for 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.

Resources

About

🦀 Learning Rust because it's cool

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages