← All Workshops

MudEngine Part 11: Peer-to-Peer with iroh

Step 12 / 14

Lint with Clippy

Every part so far ended with cargo clippy at zero warnings, and this one is no different — the P2P layer is the densest code in the series, so it deserves the check. Run it from mud-engine/:

cargo check
cargo clippy

Cargo.toml sets [lints.rust] unused = "allow" (Part 6's legacy), but there is no [lints.clippy] section — the default lint set applies, and the blocks in this part are written to satisfy it:

  • while let Some(Ok(event)) = receiver.next().await — the mesh stream yields Results; this idiomatic let-chain (not a .map(|e| e.unwrap()) or a loop/match pair) keeps the happy path flat while Err(_) => continue treats malformed packets as noise.
  • if let Some(room) = self.state.rooms.iter_mut().find(|r| r.id == ...) && !room.exits... — the quest code's nested if/if from Part 9 stays folded into guard let-chains (that was the collapsible_if fix).
  • .is_some_and(|items| items.iter().any(...)) for boolean predicates instead of .map_or(false, ...) (unnecessary_map_or).
  • No expect-on-user-input in the hot path: node-id parsing and topic subscription return Results mapped to format!(...) errors that surface on the connection screen instead of panicking.

If Clippy flags something not covered here, prefer the teaching fix (the shape that matches engine.rs / net.rs) over a #[allow].

Check, lint, and prove the mesh
cargo check && cargo clippy && cargo test host_and_client
💡 cargo test proves the P2P path

cargo test host_and_client is the workshop's proof that the mesh actually works: it boots a real host and a real client inside one test process and pumps a Join and a Move across the gossip topic (see the 'gossip round-trip test' callout). A green test here means two separate desktop processes will connect too — same code, same runtime, just two windows.

Step 12 / 14