Expand examples with routing and middleware demo#114
Conversation
Reviewer's GuideThis PR enhances the example suite by improving README instructions for running echo and ping-pong examples, introducing a fully featured ping-pong implementation with error handling and configurable bind address, refactoring duplicate error encoding logic, and adding structured documentation for the ping-pong example. Class diagram for the new ping-pong exampleclassDiagram
class Ping {
+u32 0
+to_bytes()
+from_bytes()
}
class Pong {
+u32 0
+to_bytes()
+from_bytes()
}
class ErrorMsg {
+String 0
+to_bytes()
+from_bytes()
}
class PongMiddleware {
}
class PongService {
+inner: S
+call(req: ServiceRequest) Result<ServiceResponse, Infallible>
}
class Logging {
}
class LoggingService {
+inner: S
+call(req: ServiceRequest) Result<ServiceResponse, Infallible>
}
class HandlerService {
+id()
+from_service(id, service)
}
PongMiddleware --|> Transform
PongService --|> Service
Logging --|> Transform
LoggingService --|> Service
HandlerService <.. PongService : inner
HandlerService <.. LoggingService : inner
PongMiddleware ..> HandlerService : transform
Logging ..> HandlerService : transform
WireframeApp <.. build_app : factory
WireframeServer <.. main : uses
build_app --> WireframeApp
main --> WireframeServer
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis update introduces new example documentation and code for a ping/pong protocol using the Wireframe framework. The README and roadmap are updated to reference these examples. The ping/pong example demonstrates routing, serialisation, and middleware, with detailed explanations and diagrams provided in a new markdown file. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant WireframeServer
participant PongMiddleware
participant LoggingMiddleware
participant HandlerService
Client->>WireframeServer: Send Ping (bincode)
WireframeServer->>LoggingMiddleware: Forward raw request
LoggingMiddleware->>PongMiddleware: Forward request
PongMiddleware->>HandlerService: Call handler (no-op)
HandlerService-->>PongMiddleware: Return ()
PongMiddleware->>PongMiddleware: Decode Ping, increment, encode Pong/Err
PongMiddleware-->>LoggingMiddleware: Return encoded Pong/Err
LoggingMiddleware->>LoggingMiddleware: Log request/response
LoggingMiddleware-->>WireframeServer: Return response
WireframeServer-->>Client: Send Pong/Error (bincode)
Poem
✨ Finishing Touches🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Hey @leynos - I've reviewed your changes - here's some feedback:
- In ping_pong.rs, consider extracting the repeated error‐encoding logic in PongService into a small helper (e.g.
fn error_frame(msg: impl AsRef<str>) -> Vec<u8>) to reduce duplication and improve readability. - For the example’s CLI, you could replace manual
std::env::args()parsing with a lightweight flags library (like clap) to make bind‐address overrides more robust and pave the way for future options. - The Mermaid diagram in examples/ping_pong.md may not render in all Markdown viewers—consider noting the Mermaid requirement or embedding a rendered image for broader compatibility.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In ping_pong.rs, consider extracting the repeated error‐encoding logic in PongService into a small helper (e.g. `fn error_frame(msg: impl AsRef<str>) -> Vec<u8>`) to reduce duplication and improve readability.
- For the example’s CLI, you could replace manual `std::env::args()` parsing with a lightweight flags library (like clap) to make bind‐address overrides more robust and pave the way for future options.
- The Mermaid diagram in examples/ping_pong.md may not render in all Markdown viewers—consider noting the Mermaid requirement or embedding a rendered image for broader compatibility.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…d-middleware-demo
Summary
HandlerServiceisn’t generic when wrapping servicesTesting
mdformat-all README.md docs/*.md examples/ping_pong.rs examples/echo.rs examples/ping_pong.mdmarkdownlint --fix AGENTS.md CHANGELOG.md README.md docs/mocking-network-outages-in-rust.md docs/preamble-validator.md docs/roadmap.md docs/rust-binary-router-library-design.md docs/rust-testing-with-rstest-fixtures.md examples/ping_pong.mdnixie README.md docs/*.md examples/ping_pong.mdmake fmtmake lintmake testhttps://chatgpt.com/codex/tasks/task_e_6857265325588322a829a52b18a77a13
Summary by Sourcery
Provide a new ping-pong example with configurable server address and improved error handling, enhance the echo example instructions, and update related documentation accordingly.
New Features:
Enhancements:
Documentation:
Summary by CodeRabbit
Documentation
New Features