Skip to content

Conversation

leynos
Copy link
Owner

@leynos leynos commented Jun 12, 2025

Summary

  • standardize trait definitions per roadmap
  • add FrameProcessor, state extractor, and middleware traits
  • mark trait task complete in roadmap

Testing

  • cargo clippy -- -D warnings
  • cargo test
  • npx --yes markdownlint-cli2 '**/*.md'

https://chatgpt.com/codex/tasks/task_e_684aab5541f48322bb628374734631cb

Summary by Sourcery

Implement foundational traits for message extraction, framing, and middleware; register new modules, update server defaults, dependencies, and documentation

New Features:

  • Add FromMessageRequest trait and SharedState extractor utilities
  • Implement FrameProcessor trait with async encode/decode methods
  • Introduce Service and Transform middleware traits with ServiceRequest, ServiceResponse, and Next types

Enhancements:

  • Ensure WireframeServer always has at least one worker and refine API examples in documentation
  • Export extractor, frame, and middleware modules in lib.rs
  • Mark standardize trait definitions item as complete in the roadmap

Build:

  • Add async-trait and bytes dependencies to Cargo.toml

Documentation:

  • Clarify code examples in server API docs and update design documentation

Tests:

  • Add unit tests for Payload extractor operations

Summary by CodeRabbit

  • New Features
    • Introduced new modules for data extraction, frame processing, and middleware, expanding the available API.
    • Added abstractions for extracting data from messages, processing frames asynchronously, and building middleware chains.
  • Documentation
    • Updated the roadmap to mark "Standardize supporting trait definitions" as complete.
    • Improved and expanded documentation for server configuration methods and usage examples.
  • Chores
    • Added new dependencies to support asynchronous traits and byte operations.
  • Refactor
    • Exposed new modules in the public API for broader functionality.
    • Simplified the message extraction trait interface from asynchronous to synchronous.
  • Tests
    • Included unit tests for payload data handling.

Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 18 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 601045b and b711bcf.

📒 Files selected for processing (1)
  • src/middleware.rs (1 hunks)

Walkthrough

This update introduces new modules for extractors, frame processing, and middleware, expanding the crate's public API. It adds dependencies on async-trait and bytes, implements core abstractions for async middleware, message extraction, and frame encoding/decoding, and updates documentation. The implementation of WireframeServer::new is removed, leaving only its documentation.

Changes

File(s) Change Summary
Cargo.toml Added async-trait and bytes as dependencies.
docs/roadmap.md Marked "Standardise supporting trait definitions" as complete in the roadmap checklist and Americanised spelling.
src/extractor.rs New file: Introduces MessageRequest, Payload, FromMessageRequest trait, and SharedState abstraction.
src/frame.rs New file: Adds FrameProcessor trait for async frame encoding/decoding.
src/lib.rs Publicly exposes new modules: extractor, frame, and middleware.
src/middleware.rs New file: Implements async middleware system with Service, Transform, Next, and request/response types.
src/server.rs Removes implementation of WireframeServer::new; expands and clarifies documentation for server methods.
docs/rust-binary-router-library-design.md Updates FromMessageRequest trait to synchronous interface, removing async future-based method.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Middleware
    participant Service

    Client->>Middleware: Send ServiceRequest
    Middleware->>Service: Next::call(ServiceRequest)
    Service-->>Middleware: ServiceResponse / Error
    Middleware-->>Client: ServiceResponse / Error
Loading
sequenceDiagram
    participant Handler
    participant Extractor
    participant Payload

    Handler->>Extractor: from_message_request(&MessageRequest, &mut Payload)
    Extractor->>Payload: advance / remaining
    Extractor-->>Handler: Extracted value or Error
Loading

Possibly related PRs

Poem

In bytes and traits, the changes grow,
Middleware chains begin to flow.
Extractors pluck from payload streams,
Frames are processed—async dreams!
With docs refreshed and modules new,
This rabbit hops to code anew.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

sourcery-ai bot commented Jun 12, 2025

Reviewer's Guide

This PR establishes the core trait foundations by adding extractor, frame-processing, and middleware modules, standardizes server worker defaults and examples, updates documentation and roadmap status, and introduces new dependencies to support async traits and byte handling.

Sequence diagram for the Middleware execution flow

sequenceDiagram
    title Middleware Execution Flow
    participant Client
    participant Middleware
    participant NextService as "Next Service / Handler"

    Client->>Middleware: call(request)
    Middleware->>Middleware: Pre-request processing
    Middleware->>NextService: next.call(request)
    NextService-->>Middleware: Result~ServiceResponse, Error~
    Middleware->>Middleware: Post-request processing
    Middleware-->>Client: Result~ServiceResponse, Error~
Loading

File-Level Changes

Change Details Files
Introduce foundational trait modules for extraction, framing, and middleware
  • Add extractor module with MessageRequest, Payload, FromMessageRequest trait, SharedState and unit tests
  • Add frame module defining FrameProcessor trait with async decode/encode methods
  • Add middleware module with ServiceRequest, ServiceResponse, Next combinator, Service and Transform traits
  • Expose new modules in lib.rs
src/extractor.rs
src/frame.rs
src/middleware.rs
src/lib.rs
Standardize server worker count and refine code examples
  • Enforce minimum of one worker via num_cpus().max(1)
  • Update new and workers methods to use consistent code fences (no_run and ignore)
  • Revise example snippets and documentation comments in server.rs
src/server.rs
Update documentation and mark roadmap task complete
  • Mark 'Standardize supporting trait definitions' as complete in roadmap.md
  • Adjust extractor trait in design docs from async Future to synchronous Result
  • Refine markdown formatting in rust-binary-router-library-design.md
docs/roadmap.md
docs/rust-binary-router-library-design.md
Add dependencies for async traits and byte operations
  • Include async-trait crate to support async trait definitions
  • Add bytes crate for frame buffer handling
Cargo.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/extractor.rs:15` </location>
<code_context>
+
+/// Raw payload buffer handed to extractors.
+#[derive(Default)]
+pub struct Payload<'a> {
+    /// Incoming bytes not yet processed.
+    pub data: &'a [u8],
</code_context>

<issue_to_address>
Add methods to advance through the payload

Consider implementing an `advance(count: usize)` method to allow updating the internal slice and tracking how much of the payload has been consumed.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
#[derive(Default)]
pub struct Payload<'a> {
    /// Incoming bytes not yet processed.
    pub data: &'a [u8],
}
=======
#[derive(Default)]
pub struct Payload<'a> {
    /// Incoming bytes not yet processed.
    pub data: &'a [u8],
}

impl<'a> Payload<'a> {
    /// Advances the payload by `count` bytes, consuming that many bytes from the front.
    pub fn advance(&mut self, count: usize) {
        let len = self.data.len();
        let n = count.min(len);
        self.data = &self.data[n..];
    }

    /// Returns the number of bytes remaining in the payload.
    pub fn remaining(&self) -> usize {
        self.data.len()
    }
}
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `src/middleware.rs:50` </location>
<code_context>
+
+/// Factory for wrapping services with middleware.
+#[async_trait]
+pub trait Transform<S>: Send + Sync
+where
+    S: Service,
</code_context>

<issue_to_address>
Rename associated `Service` type for clarity

Consider renaming the `Service` type alias within `Transform` to avoid confusion with the `Service` trait, such as `Output` or `Transformed`, for better readability.

Suggested implementation:

```rust
    /// Wrapped service produced by the middleware.
    type Output: Service;

```

```rust
    /// Create a new middleware service wrapping `service`.
    async fn transform(&self, service: S) -> Self::Output;

```
</issue_to_address>

### Comment 3
<location> `src/extractor.rs:35` </location>
<code_context>
+
+/// Shared application state accessible to handlers.
+#[derive(Clone)]
+pub struct SharedState<T>(Arc<T>);
+
+impl<T> SharedState<T> {
</code_context>

<issue_to_address>
Consider bounding `T` with `Send + Sync`

Enforcing `T: Send + Sync` on `SharedState` helps ensure safe usage in concurrent async contexts.

Suggested implementation:

```rust
use std::marker::PhantomData;

/// Shared application state accessible to handlers.
#[derive(Clone)]
pub struct SharedState<T: Send + Sync>(Arc<T>);

impl<T: Send + Sync> SharedState<T> {

```

```rust
impl<T: Send + Sync> std::ops::Deref for SharedState<T> {
    type Target = T;

```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

coderabbitai bot added a commit that referenced this pull request Jun 12, 2025
…cessor`

Docstrings generation was requested by @leynos.

* #8 (comment)

The following files were modified:

* `src/extractor.rs`
* `src/middleware.rs`
* `src/server.rs`
Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

Note

Generated docstrings for this pull request at #9

…cessor` (#9)

Docstrings generation was requested by @leynos.

* #8 (comment)

The following files were modified:

* `src/extractor.rs`
* `src/middleware.rs`
* `src/server.rs`

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@leynos
Copy link
Owner Author

leynos commented Jun 12, 2025

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Test module is nested inside impl SharedState, causing invalid syntax (link)

General comments:

  • The #[must_use] attribute is currently floating before the tests module—move it to directly annotate the SharedState::new method so it applies correctly.
  • Your doc example for SharedState::new uses assert_eq! which requires Debug + PartialEq on SharedState; either derive those traits or adjust the example to avoid a compile error.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `#[must_use]` attribute is currently floating before the tests module—move it to directly annotate the `SharedState::new` method so it applies correctly.
- Your doc example for `SharedState::new` uses `assert_eq!` which requires `Debug + PartialEq` on `SharedState`; either derive those traits or adjust the example to avoid a compile error.

## Individual Comments

### Comment 1
<location> `src/extractor.rs:58` </location>
<code_context>
+    /// Construct a new [`SharedState`].
+    #[must_use]
+
+#[cfg(test)]
+mod tests {
+    use super::*;
</code_context>

<issue_to_address>
Test module is nested inside impl SharedState, causing invalid syntax

Move the `#[cfg(test)] mod tests` block outside the `impl SharedState` to resolve the syntax error and ensure correct scoping of methods.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@leynos
Copy link
Owner Author

leynos commented Jun 12, 2025

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.

  • In extractor.rs the #[cfg(test)] module is nested inside the SharedState impl—please move the tests outside the impl block and adjust indentation so it compiles correctly.
  • The MessageRequest struct still has a TODO placeholder; either flesh out its fields or remove the comment to avoid confusion.
  • The server.rs docs repeat example blocks all marked ignore; consolidate them and convert at least one into a real doc test for clearer documentation.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In extractor.rs the #[cfg(test)] module is nested inside the SharedState impl—please move the tests outside the impl block and adjust indentation so it compiles correctly.
- The `MessageRequest` struct still has a TODO placeholder; either flesh out its fields or remove the comment to avoid confusion.
- The server.rs docs repeat example blocks all marked `ignore`; consolidate them and convert at least one into a real doc test for clearer documentation.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@leynos
Copy link
Owner Author

leynos commented Jun 12, 2025

@sourcery-ai review

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

🔭 Outside diff range comments (1)
src/server.rs (1)

31-48: ⚠️ Potential issue

WireframeServer::new implementation removed and docs malformed

  1. The method is only documented – the actual pub fn new is gone, so every WireframeServer::new(..) call will fail to compile.
  2. The code block started with ```no_run is never closed, producing an “unclosed block” rustdoc error.

Apply the following patch:

@@
 /// The server is initialised with a default worker count equal to the number of CPU cores.
 ///
 /// ```no_run
@@
-///         .await
-/// }
-/// A new `WireframeServer` instance with the updated worker count.
+///         .await
+/// }
+/// ```
+
+    /// Creates a new `WireframeServer` with sane defaults.
+    pub fn new(factory: F) -> Self {
+        Self {
+            factory,
+            listener: None,
+            workers: num_cpus::get().max(1),
+        }
+    }

This restores functionality and fixes the doc markup.

♻️ Duplicate comments (2)
src/extractor.rs (1)

71-91: ⚠️ Potential issue

Module declared inside impl block breaks compilation

#[cfg(test)] mod tests { .. } is placed inside the impl SharedState<T> block.
Rust does not allow a mod item inside an impl, so the file will fail to compile.

 impl<T: Send + Sync> SharedState<T> {
     /* … existing methods … */
-    #[cfg(test)]
-    mod tests {
+}
+
+#[cfg(test)]
+mod tests {
     use super::*;
     /* … */
 }

Move the whole test module outside the impl to restore valid syntax.

src/middleware.rs (1)

82-84: Name clash between Service trait and associated type Output

The associated type is still called Output, which avoids the previous Service/Service shadowing but is rather generic. Consider a more descriptive name such as Wrapped or Transformed for clarity.

-    /// Wrapped service produced by the middleware.
-    type Output: Service;
+    /// Service produced by the middleware.
+    type Wrapped: Service;

This was suggested earlier and remains applicable.

🧹 Nitpick comments (4)
Cargo.toml (1)

12-13: Pinning to a hard-coded patch version can hinder semver compatibility

Unless you rely on a specific bug-fix, "0.1" and "1" already resolve to the latest compatible patch. Locking further with =0.1.0 or a fixed sub-minor can make downstream upgrades noisy. Consider using the caret syntax (the default) or adding a cargo update/cargo deny policy instead.

docs/roadmap.md (1)

25-28: Spelling consistency: “Standardise” vs “Standardize”

Project prose elsewhere (e.g. README) uses American spelling. Decide on one convention (en-GB or en-US) and stick to it to avoid grep-by-term surprises.

🧰 Tools
🪛 LanguageTool

[style] ~25-~25: Would you like to use the Oxford spelling “Standardize”? The spelling ‘Standardise’ is also correct.
Context: ...epting new connections. - [x] Standardise supporting trait definitions. P...

(OXFORD_SPELLING_Z_NOT_S)

src/frame.rs (1)

17-22: Use bytes::BytesMut instead of Vec<u8> for zero-copy efficiency

Vec<u8> incurs reallocations; the rest of the crate already depends on bytes. Returning/accepting &mut BytesMut (or Bytes) gives you cheap slicing and reference-counted sharing, aligning with Tokio-style codecs.

-    async fn encode(&mut self, frame: &Self::Frame, dst: &mut Vec<u8>) -> Result<(), Self::Error>;
+    async fn encode(
+        &mut self,
+        frame: &Self::Frame,
+        dst: &mut bytes::BytesMut,
+    ) -> Result<(), Self::Error>;

Applies analogously to decode.

src/middleware.rs (1)

45-60: Doctest snippet will not compile under rustdoc

Hidden lines beginning with # are still compiled.
your_crate::{ServiceRequest, ServiceResponse, Next, Service} is not a valid path in the current crate, therefore cargo test --doc will fail.

Either:

-/// # use your_crate::{ServiceRequest, ServiceResponse, Next, Service};
+/// ```ignore
+/// use my_crate::{ServiceRequest, ServiceResponse, Next, Service};
+/// ```

or add the ignore flag to the whole example.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 51aa806 and ea3a7a8.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • Cargo.toml (1 hunks)
  • docs/roadmap.md (1 hunks)
  • src/extractor.rs (1 hunks)
  • src/frame.rs (1 hunks)
  • src/lib.rs (1 hunks)
  • src/middleware.rs (1 hunks)
  • src/server.rs (3 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/roadmap.md

[style] ~25-~25: Would you like to use the Oxford spelling “Standardize”? The spelling ‘Standardise’ is also correct.
Context: ...epting new connections. - [x] Standardise supporting trait definitions. P...

(OXFORD_SPELLING_Z_NOT_S)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: coverage
🔇 Additional comments (1)
src/lib.rs (1)

2-5: Ensure matching modules exist and are compiled

pub mod extractor; and pub mod middleware; must have corresponding mod.rs or *.rs files at compile time. CI will break otherwise. Double-check that they’re committed and feature-gated appropriately.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.

  • In extractor.rs the #[must_use] attribute appears to be dangling and the tests module is nested inside the SharedState impl—move the tests out of the impl block and place the attribute directly above the new method.
  • There are duplicate # Examples blocks in server.rs for methods like workers, bind, and run—remove the redundant code snippets to keep the docs concise.
  • The async FromMessageRequest::from_message_request signature uses a mutable borrow of Payload but protocols generated by async_trait require 'static futures; consider adjusting lifetimes or switching to a synchronous extractor API to avoid potential borrow conflicts.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In extractor.rs the `#[must_use]` attribute appears to be dangling and the `tests` module is nested inside the `SharedState` impl—move the tests out of the impl block and place the attribute directly above the `new` method.
- There are duplicate `# Examples` blocks in server.rs for methods like `workers`, `bind`, and `run`—remove the redundant code snippets to keep the docs concise.
- The async `FromMessageRequest::from_message_request` signature uses a mutable borrow of `Payload` but protocols generated by `async_trait` require `'static` futures; consider adjusting lifetimes or switching to a synchronous extractor API to avoid potential borrow conflicts.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

Note

Generated docstrings for this pull request at #10

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • new constructor initializations are missing (link)
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/server.rs:40` </location>
<code_context>
     /// ```
-    /// let server = WireframeServer::new(|| WireframeApp::default());
-    /// ```
-    pub fn new(factory: F) -> Self {
-        Self {
-            factory,
-            listener: None,
-            workers: num_cpus::get(),
-        }
-    }
+            workers: num_cpus::get().max(1),
</code_context>

<issue_to_address>
`new` constructor initializations are missing

Please restore the `factory` and `listener` initializations in the `new` method to ensure `WireframeServer` is constructed correctly.
</issue_to_address>

### Comment 2
<location> `src/middleware.rs:30` </location>
<code_context>
+/// use wireframe::middleware::{ServiceRequest, ServiceResponse, Next, Service};
+/// ```
+    /// Service produced by the middleware.
+    type Wrapped: Service;
+    async fn transform(&self, service: S) -> Self::Wrapped;
+    /// let service = MyService::default();
+    /// let next = Next::new(&service);
</code_context>

<issue_to_address>
Invalid associated items inside `impl Next`

Move `type Wrapped` and `async fn transform` to a trait, such as `Transform`, or remove them from the `impl Next` block. Only `new` and `call` should be defined in `Next`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines -40 to -45
pub fn new(factory: F) -> Self {
Self {
factory,
listener: None,
workers: num_cpus::get(),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): new constructor initializations are missing

Please restore the factory and listener initializations in the new method to ensure WireframeServer is constructed correctly.

Comment on lines +30 to +31
type Wrapped: Service;
async fn transform(&self, service: S) -> Self::Wrapped;
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Invalid associated items inside impl Next

Move type Wrapped and async fn transform to a trait, such as Transform, or remove them from the impl Next block. Only new and call should be defined in Next.

@leynos
Copy link
Owner Author

leynos commented Jun 13, 2025

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • The new constructor is incomplete; missing Self { ... } wrapper (link)

General comments:

  • The #[cfg(test)] mod tests is declared inside the SharedState impl block—move it outside so the impl and tests compile correctly.
  • The Next struct in middleware has duplicate/invalid transform definitions and no clear new constructor—consolidate into one correct API and ensure it compiles.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The #[cfg(test)] mod tests is declared inside the SharedState impl block—move it outside so the impl and tests compile correctly.
- The Next struct in middleware has duplicate/invalid transform definitions and no clear `new` constructor—consolidate into one correct API and ensure it compiles.

## Individual Comments

### Comment 1
<location> `src/server.rs:41` </location>
<code_context>
-            workers: num_cpus::get(),
-        }
-    }
+            workers: num_cpus::get().max(1),

-    /// Set the number of worker tasks to spawn.
</code_context>

<issue_to_address>
The `new` constructor is incomplete; missing `Self { ... }` wrapper

Please wrap the fields in `Self { factory, listener: None, workers: ... }` to correctly construct the struct.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@leynos
Copy link
Owner Author

leynos commented Jun 13, 2025

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@leynos leynos merged commit 59b526b into main Jun 13, 2025
2 of 3 checks passed
@leynos leynos deleted the codex/standardise-trait-definitions-for-frameprocessor branch June 13, 2025 07:07
@leynos
Copy link
Owner Author

leynos commented Jun 13, 2025

@coderabbitai docstrings

Copy link
Contributor

coderabbitai bot commented Jun 13, 2025

Tip

For best results, initiate chat on the files or code changes.

@leynos Sure! I’ll put together a plan to enrich the new public APIs with comprehensive Rust-style doc comments. I’ll prepare patches for

• src/extractor.rs (MessageRequest, Payload, FromMessageRequest, SharedState)
• src/frame.rs (FrameProcessor)
• src/middleware.rs (ServiceRequest, ServiceResponse, Next, Service, Transform)

and make sure each item includes a concise summary, parameter / return sections, and examples where helpful.

I’ll post the detailed change plan and code snippets in the next message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant