Rust Learning Log

Pattern Matching Feels Better Than If Else Sprawl

Notes on why match expressions already feel cleaner than the branching habits I bring in from other languages.

Topic: Pattern Matching Status: Worth practicing more matchenumscontrol-flow

One of the first things that felt genuinely pleasant in Rust was match.

What clicked

  • It pushes me toward handling the full shape of a value.
  • It makes enum-based code feel intentional instead of defensive.
  • It reads like the compiler is asking, “did you really think through every case?”
enum BuildState {
	Ready,
	Running,
	Failed,
}

fn label(state: BuildState) -> &'static str {
	match state {
		BuildState::Ready => "ready",
		BuildState::Running => "running",
		BuildState::Failed => "failed",
	}
}

What I want to keep doing

When a set of values has a real shape, use an enum and let match force clarity.

What to review later

I still need more repetition with pattern matching on Option, Result, and nested enum data.

Back to Rust log