MudEngine Part 11: Peer-to-Peer with iroh
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 yieldsResults; this idiomatic let-chain (not a.map(|e| e.unwrap())or aloop/matchpair) keeps the happy path flat whileErr(_) => continuetreats malformed packets as noise.if let Some(room) = self.state.rooms.iter_mut().find(|r| r.id == ...) && !room.exits...— the quest code's nestedif/iffrom Part 9 stays folded into guard let-chains (that was thecollapsible_iffix)..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 returnResults mapped toformat!(...)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].
cargo check && cargo clippy && cargo test host_and_clientcargo 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.