Skip to content

Conversation

@kixelated
Copy link
Collaborator

Replaced verbose match statements that extract a value and early return
on the alternative branch with the more concise let-else syntax.

Changes include:

  • moq-relay: Simplified Option and Result matching in web.rs, auth.rs,
    cluster.rs
  • moq-lite: Simplified error handling patterns in model (track.rs,
    frame.rs, group.rs) and ietf modules (subscriber.rs, publisher.rs)
  • hang: Simplified nested matches in annexb.rs and group.rs

This improves code readability while maintaining the same behavior.
All tests pass.

Replaced verbose match statements that extract a value and early return
on the alternative branch with the more concise let-else syntax.

Changes include:
- moq-relay: Simplified Option and Result matching in web.rs, auth.rs,
  cluster.rs
- moq-lite: Simplified error handling patterns in model (track.rs,
  frame.rs, group.rs) and ietf modules (subscriber.rs, publisher.rs)
- hang: Simplified nested matches in annexb.rs and group.rs

This improves code readability while maintaining the same behavior.
All tests pass.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 13, 2026

Walkthrough

This pull request refactors control flow patterns across multiple Rust modules by systematically replacing pattern matching blocks with let-else constructs for handling Option and Result types. Examples include converting match statements to let Some and let-Ok patterns with else branches for early returns, simplifying prefix checking, and streamlining error handling paths. The refactoring affects files in the moq-lite, moq-relay, and hang crates. All changes maintain existing semantics and behavior while altering code style and readability.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change—refactoring match statements to use let-else syntax across multiple files.
Description check ✅ Passed The description clearly explains the refactoring effort, lists affected files and modules, and notes that tests pass.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
rs/moq-relay/src/cluster.rs (1)

204-208: The .unwrap() on line 206 assumes the cancelled node exists in active.

While the current code flow appears safe (nodes are only added after the self-check on lines 199-202), using .unwrap() here could panic if the invariant is ever violated. Consider using if let Some(handle) = active.remove(...) for defensive coding.

♻️ Suggested defensive handling
 		let Some(origin) = origin else {
 			tracing::info!(%node, "origin cancelled");
-			active.remove(node.as_str()).unwrap().abort();
+			if let Some(handle) = active.remove(node.as_str()) {
+				handle.abort();
+			}
 			continue;
 		};
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 411e302 and db3ba37.

📒 Files selected for processing (10)
  • rs/hang/src/import/annexb.rs
  • rs/hang/src/model/group.rs
  • rs/moq-lite/src/ietf/publisher.rs
  • rs/moq-lite/src/ietf/subscriber.rs
  • rs/moq-lite/src/model/frame.rs
  • rs/moq-lite/src/model/group.rs
  • rs/moq-lite/src/model/track.rs
  • rs/moq-relay/src/auth.rs
  • rs/moq-relay/src/cluster.rs
  • rs/moq-relay/src/web.rs
🧰 Additional context used
📓 Path-based instructions (2)
rs/**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

rs/**/*.rs: Use cargo for Rust-specific operations
Rust tests should be integrated within source files rather than in separate test files

Files:

  • rs/moq-lite/src/ietf/publisher.rs
  • rs/moq-lite/src/ietf/subscriber.rs
  • rs/moq-lite/src/model/track.rs
  • rs/moq-relay/src/auth.rs
  • rs/moq-lite/src/model/group.rs
  • rs/hang/src/model/group.rs
  • rs/moq-relay/src/cluster.rs
  • rs/hang/src/import/annexb.rs
  • rs/moq-lite/src/model/frame.rs
  • rs/moq-relay/src/web.rs
rs/hang/**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

Media-specific encoding/decoding should be implemented in the hang layer on top of moq-lite

Files:

  • rs/hang/src/model/group.rs
  • rs/hang/src/import/annexb.rs
🧠 Learnings (1)
📚 Learning: 2025-12-20T13:22:14.684Z
Learnt from: Frando
Repo: moq-dev/moq PR: 794
File: justfile:150-156
Timestamp: 2025-12-20T13:22:14.684Z
Learning: In the moq project, for iroh connections, the endpoint ID (public key) in the justfile is derived from the secret key configured in dev/relay.toml. They form an Ed25519 keypair, not identical values.

Applied to files:

  • rs/moq-relay/src/auth.rs
🧬 Code graph analysis (2)
rs/moq-relay/src/auth.rs (2)
rs/moq-token/src/key.rs (1)
  • from_file (216-222)
rs/moq-lite/src/model/origin.rs (3)
  • root (281-306)
  • root (432-434)
  • root (532-534)
rs/moq-relay/src/cluster.rs (1)
rs/moq-lite/src/model/origin.rs (3)
  • root (281-306)
  • root (432-434)
  • root (532-534)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Check
🔇 Additional comments (15)
rs/moq-lite/src/ietf/subscriber.rs (2)

79-81: LGTM!

The let-else pattern is idiomatic for this early-return scenario. The semantics are preserved—returning Err(Error::InvalidRole) when origin is None.


116-118: LGTM!

Consistent application of the let-else pattern as in start_announce.

rs/moq-lite/src/model/frame.rs (2)

166-171: LGTM!

The let-else pattern correctly handles the RecvError case (sender dropped) by returning Error::Cancel, then separately checks for application-level errors in state.closed. Semantics preserved.


184-189: LGTM!

Consistent pattern with read_chunks—clean separation between channel-level errors and application-level closed state.

rs/moq-lite/src/model/track.rs (1)

168-176: LGTM!

The let-else refactor correctly handles the channel closure case. The subsequent match on state.closed appropriately handles clean termination vs. error propagation.

rs/hang/src/import/annexb.rs (1)

21-26: LGTM!

Clean application of let-else for the nested Result<Option<_>> pattern. The ? propagates errors while let-else handles the None case with an early return.

rs/moq-lite/src/model/group.rs (1)

182-185: LGTM!

The let-else pattern cleanly handles the None case for self.active. The variable shadowing on line 185 (frame becomes Bytes from read_all()) is intentional and idiomatic here.

rs/moq-lite/src/ietf/publisher.rs (1)

82-89: LGTM!

The let-else refactoring correctly handles the None case by sending a SubscribeError with a 404 status and returning early. This is semantically equivalent to the previous match statement while being more concise and readable.

rs/hang/src/model/group.rs (1)

63-66: LGTM!

The let-else pattern correctly handles the end-of-stream case by returning Ok(None) when no more frames are available. The error propagation via ? happens before the pattern match, preserving the original error handling semantics.

rs/moq-relay/src/auth.rs (2)

71-71: LGTM!

The method chain as_deref().map(...).transpose()? is idiomatic Rust for conditionally applying a fallible operation to an Option. This correctly handles: NoneNone, Some(path) with successful load → Some(key), and Some(path) with failed load → propagates error.


114-116: LGTM!

The let-else pattern correctly handles the path prefix validation, returning AuthError::IncorrectRoot when the URL path doesn't match the token's root claim.

rs/moq-relay/src/cluster.rs (1)

119-130: LGTM!

The let-else with .filter() elegantly combines the root existence check and self-node comparison. If no root is configured or if we are the root node ourselves, the else branch correctly runs as root and waits for leaf connections.

rs/moq-relay/src/web.rs (3)

235-237: LGTM!

The let-else pattern cleanly handles the unauthorized case when no subscriber origin is available for the given token.


268-270: LGTM!

Consistent with the pattern used in serve_announced for authorization checking.


283-288: LGTM!

The two-stage let-else pattern cleanly separates error semantics: Err from next_group() indicates a transport/protocol failure (500), while Ok(None) indicates no group is available yet (404). This is clearer than a nested match and correctly maps to HTTP status codes.

@kixelated kixelated merged commit 189f6f6 into main Jan 13, 2026
1 check passed
@kixelated kixelated deleted the claude/simplify-match-statements-8mGnp branch January 13, 2026 09:34
@moq-bot moq-bot bot mentioned this pull request Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants