Files
kiskaadee b768383767 docs(study): add active-learning template, Ch 1 example, and Ch 2 NixOS setup
- Add .gitignore to exclude local book PDFs and compiled Rust artifacts
- Document reference book metadata and 3-part study loop in README.md and NOTES_TEMPLATE.md
- Rewrite 01-introduction-to-rust/README.md as a concise active-learning example with mylib/ listings
- Adapt 02-getting-started/README.md to template with NixOS Home Manager toolchain setup
2026-11-27 23:58:09 -05:00
..

2. Getting Started

Reference: Donis Marshall, Programming with Rust (2024) — Chapter 2 Phase: 1 (Basics & Tooling) | Code: (add crate/file link as you go)

1. Mental Model (My Own Words)

  • Core idea: Getting a working Rust toolchain, compiling with rustc vs. managing projects with cargo, and understanding the entry point (main), libraries, comments, and CLI arguments.
  • Installing Rust on NixOS (instead of rustup):
    • On macOS/Windows/traditional Linux, rustup downloads toolchains into ~/.cargo/bin and switches between stable, beta, and nightly.
    • On NixOS, Home Manager manages the global toolchain declaratively in ~/Config/home/dev.nix (cargo, rustc, rustfmt, clippy, rust-analyzer, and gcc as linker, exposed in /etc/profiles/per-user/$USER/bin/). Installing rustup alongside Nix-managed binaries is redundant and risks PATH shadowing.
    • Per-project overrides: When a project needs a pinned Rust version or cross-compilation targets (what the book calls "Advanced Rustup"), use a per-project flake.nix devShell instead of rustup toolchain.
    • User-installed binaries: ~/.cargo/bin stays on PATH for tools installed via cargo install.
  • Remaining Chapter 2 topics to distill as I read:
    • rustc direct compile vs. cargo new / cargo build / cargo run
    • Binary (src/main.rs) vs. Library (src/lib.rs) crates and published crates (crates.io)
    • main() signatures, doc comments (///), and std::env::args()

2. Break-It Experiments

Ideas to test in cargo as I work through the chapter:

  • Experiment 1 (rustc vs cargo): Compile a standalone hello.rs with rustc, then create a Cargo package and compare what Cargo.toml / target/ generate.
    • Result / rustc message: (fill in)
    • Takeaway: (fill in)
  • Experiment 2 (Tooling checks): Run rustc --version, cargo --version, cargo clippy, and cargo fmt --check on a tiny crate.
    • Result: (fill in)
    • Takeaway: (fill in)

3. Friction Log ("Gotchas")

  • NixOS clippy binary name: which clippy fails because the subcommand binary is cargo-clippy—always invoke it as cargo clippy.
  • (Add compiler/Cargo gotchas here as you hit them.)

4. Recall Prompts (Answer Without Looking)

  1. Why do we avoid rustup on NixOS when Home Manager already provides rustc and cargo, and what replaces rustup for pinned per-project toolchains?
  2. What is the difference between running rustc main.rs directly vs. cargo run?
  3. Where do cargo install binaries live, and how does PATH find them?