Skip to content

Add shared state container#75

Merged
leynos merged 5 commits intomainfrom
codex/add-shared-state-container-to-wireframeapp
Jun 19, 2025
Merged

Add shared state container#75
leynos merged 5 commits intomainfrom
codex/add-shared-state-container-to-wireframeapp

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jun 18, 2025

Summary

  • store app data in WireframeApp
  • expose shared state via MessageRequest
  • implement ExtractError and SharedState extractor
  • add tests for shared state extraction
  • document app_data usage

Testing

  • cargo clippy -- -D warnings
  • RUSTFLAGS="-D warnings" cargo test

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

Summary by Sourcery

Enable registering and extracting shared application state in WireframeApp via a new app_data API and SharedState extractor

New Features:

  • Introduce app_data builder method on WireframeApp to register shared state keyed by type
  • Add SharedState extractor and ExtractError to retrieve registered application data from MessageRequest

Documentation:

  • Document the app_data usage and SharedState extractor in design docs and README

Tests:

  • Add tests for successful and missing shared state extraction

Summary by CodeRabbit

  • New Features

    • Added support for registering and retrieving shared application state, enabling extractors to access shared data during request handling.
  • Bug Fixes

    • Fixed Markdown rendering issues in documentation bullet points.
  • Documentation

    • Improved and clarified documentation for shared state usage, builder methods, and extractor system.
  • Tests

    • Added unit tests to verify shared state extraction and error handling when state is missing.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 18, 2025

Reviewer's Guide

This PR adds a type-keyed shared state container to WireframeApp via a new app_data builder, carries registered state into MessageRequest with a state() accessor, implements a SharedState extractor (with ExtractError for missing state), updates documentation/examples to reflect the new API, and adds unit tests for extraction success and error cases.

File-Level Changes

Change Details Files
Introduce app_data builder in WireframeApp
  • Add app_data field to WireframeApp struct
  • Initialize app_data in the constructor
  • Implement app_data() method to register type-keyed state
  • Propagate app_data through build methods
src/app.rs
Extend MessageRequest with shared state support
  • Add app_data field to MessageRequest
  • Implement state() accessor returning Option<SharedState>
src/extractor.rs
Implement SharedState extractor and ExtractError
  • Define ExtractError enum with MissingState variant and impl Display/Error
  • Implement FromMessageRequest for SharedState returning ExtractError
src/extractor.rs
Update documentation to reflect new shared state API
  • Revise .app_data usage and overwrite semantics in rust-binary-router-library-design.md
  • Clarify app_data behavior and remove unnecessary .into() examples in README.md
docs/rust-binary-router-library-design.md
README.md
Add unit tests for shared state extraction
  • Test successful SharedState:: extraction from MessageRequest
  • Test missing SharedState returns ExtractError::MissingState
tests/app_data.rs

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 18, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update replaces the shared application state storage from a vector to a type-keyed hash map in both the WireframeApp builder and MessageRequest. It adds a builder method to register shared state keyed by type, implements typed extraction with error handling, and updates documentation and tests accordingly.

Changes

File(s) Change Summary
src/app.rs Changed app_data from Vec to HashMap<TypeId, Arc<dyn Any + Send + Sync>>; added app_data<T> builder method for keyed shared state registration.
src/extractor.rs Changed app_data in MessageRequest to a HashMap; added typed state<T> retrieval method; introduced ExtractError; implemented FromMessageRequest for SharedState<T> with error handling.
README.md, docs/rust-binary-router-library-design.md Updated documentation and examples to clarify keyed shared state storage, overwrite behaviour, and extractor usage.
tests/app_data.rs Added tests verifying successful shared state extraction and error handling when shared state is missing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WireframeApp
    participant MessageRequest
    participant Extractor (SharedState)
    
    User->>WireframeApp: app_data(state)
    WireframeApp->>WireframeApp: Store state in app_data (HashMap keyed by type)

    User->>WireframeApp: Build and run app
    WireframeApp->>MessageRequest: Create request with app_data

    Extractor (SharedState)->>MessageRequest: Extract SharedState<T>
    alt State found
        MessageRequest-->>Extractor (SharedState): Return SharedState<T>
    else State missing
        MessageRequest-->>Extractor (SharedState): Return ExtractError::MissingState
    end
Loading

Possibly related PRs

  • Fix compile errors and clippy #11: Refactored SharedState constructor placement in extractor.rs; related to shared state handling but focused on method location rather than extraction logic.

Poem

In the meadow of code where the shared states grow,
A rabbit hops by with new seeds to sow.
App data now shared, for all routes to see,
Extractors can nibble, as happy as can be!
If a carrot is missing, an error will say—
“No veggie for you, please try another way!” 🥕

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch codex/add-shared-state-container-to-wireframeapp

🪧 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 auto-generate unit tests to generate unit tests for 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
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

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

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

Absence of Expected Change Pattern

  • wireframe/src/extractor.rs is usually changed with: wireframe/src/middleware.rs

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

Copy link
Copy Markdown
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:28` </location>
<code_context>
+        T: Send + Sync + 'static,
+    {
+        let data: SharedState<T> = state.into();
+        self.app_data
+            .push(Arc::new(data) as Arc<dyn Any + Send + Sync>);
+        Ok(self)
</code_context>

<issue_to_address>
Potential for subtle bugs if multiple SharedState<T> are registered.

Only the first registered SharedState<T> is returned, which may be unexpected. Please document this behavior clearly or enforce that only one instance can be registered.
</issue_to_address>

### Comment 2
<location> `src/extractor.rs:23` </location>
<code_context>
+
+impl MessageRequest {
+    /// Retrieve shared state of type `T` if available.
+    #[must_use]
+    pub fn state<T>(&self) -> Option<SharedState<T>>
+    where
</code_context>

<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should be after.

Please move the #[must_use] attribute to after the function's doc comment to comply with the style guide.
</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 thread src/extractor.rs
Comment thread src/extractor.rs
Copy link
Copy Markdown
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3f43136 and 34157e3.

📒 Files selected for processing (5)
  • README.md (3 hunks)
  • docs/rust-binary-router-library-design.md (2 hunks)
  • src/app.rs (7 hunks)
  • src/extractor.rs (4 hunks)
  • tests/app_data.rs (1 hunks)
🔇 Additional comments (14)
README.md (3)

16-16: Documentation improvement.

Good fix for the markdown escaping issue that could have caused rendering problems.


36-36: API simplification reflected correctly.

The removal of .into() conversion suggests the app_data method now accepts the state directly, which simplifies the API.


49-50: Clear documentation of new functionality.

The added explanation of app_data functionality provides users with a clear understanding of how to store and retrieve shared state using the SharedState<T> extractor.

tests/app_data.rs (1)

1-31: Comprehensive test coverage for shared state extraction.

The tests effectively cover both the success case (extracting existing shared state) and the failure case (missing state returns appropriate error). The test setup using MessageRequest with manually constructed app_data ensures the extraction logic is properly validated.

docs/rust-binary-router-library-design.md (2)

629-629: Consistent with API changes.

The removal of .into() conversion aligns with the simplified app_data method signature.


791-793: Accurate description of MessageRequest enhancement.

The updated description correctly explains that MessageRequest now encapsulates both connection metadata and shared state registered via WireframeApp::app_data.

src/app.rs (4)

7-7: Appropriate imports for shared state functionality.

The added imports for std::any::Any and extractor::SharedState are necessary for the type-erased storage and shared state wrapper.

Also applies to: 13-13


34-34: Well-designed shared state storage.

Using Vec<Arc<dyn Any + Send + Sync>> for type-erased storage is a sound approach that allows multiple different types to be stored whilst maintaining thread safety.


155-172: Clean API for registering shared state.

The app_data method provides a ergonomic way to register shared state. Converting to SharedState<T> before type-erasure ensures consistent storage format. The Result return type provides forward compatibility for potential validation.


215-215: Proper state propagation in builder methods.

The app_data field is correctly propagated in builder transformation methods, ensuring shared state is preserved when changing serializers or connection types.

Also applies to: 261-261

src/extractor.rs (4)

17-19: Appropriate extension of MessageRequest.

Adding the app_data field allows shared state to be accessed during request processing whilst maintaining type safety through the type-erased storage.


75-77: Manual Clone implementation necessary.

The manual Clone implementation is required since SharedState<T> contains an Arc<T> and automatic derivation would require T: Clone, which is not needed for reference-counted data.


119-134: Well-designed error type for extraction failures.

The ExtractError enum with MissingState variant provides clear error reporting when shared state is not found. The error message includes the type name for debugging.


136-149: Correct FromMessageRequest implementation.

The implementation properly extracts shared state using the state<T> method and returns an appropriate error when the state is missing. Using std::any::type_name::<T>() in the error provides helpful debugging information.

Comment thread src/extractor.rs
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 18, 2025

@sourcery-ai review

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 18, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 18, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

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

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

Absence of Expected Change Pattern

  • wireframe/src/extractor.rs is usually changed with: wireframe/src/middleware.rs

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

Copy link
Copy Markdown
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 - here's some feedback:

  • The app_data builder method returns a Result but never actually fails; consider simplifying its signature to return Self directly until you introduce real error conditions.
  • Keying shared state by TypeId::of::<SharedState<T>>() is a bit confusing—it's more idiomatic to key by TypeId::of::<T>() and store Arc<T> directly to avoid the extra wrapper and streamline lookups.
  • Your tests use MessageRequest::default() but no Default impl exists on MessageRequest; either add a Default implementation or update the tests to construct the struct explicitly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `app_data` builder method returns a `Result` but never actually fails; consider simplifying its signature to return `Self` directly until you introduce real error conditions.
- Keying shared state by `TypeId::of::<SharedState<T>>()` is a bit confusing—it's more idiomatic to key by `TypeId::of::<T>()` and store `Arc<T>` directly to avoid the extra wrapper and streamline lookups.
- Your tests use `MessageRequest::default()` but no `Default` impl exists on `MessageRequest`; either add a `Default` implementation or update the tests to construct the struct explicitly.

## Individual Comments

### Comment 1
<location> `src/app.rs:171` </location>
<code_context>
+    ///
+    /// This function currently always succeeds but returns [`Result`] for
+    /// future flexibility.
+    pub fn app_data<T>(mut self, state: T) -> Result<Self>
+    where
+        T: Send + Sync + 'static,
</code_context>

<issue_to_address>
Returning Result<Self> is unnecessary if the function cannot fail.

Since app_data always returns Ok(self), returning Self directly would simplify the API unless you expect this method to become fallible soon.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    ///
    /// # Errors
    ///
    /// This function currently always succeeds but returns [`Result`] for
    /// future flexibility.
    pub fn app_data<T>(mut self, state: T) -> Result<Self>
    where
        T: Send + Sync + 'static,
    {
        let data: SharedState<T> = state.into();
        self.app_data.insert(
            TypeId::of::<SharedState<T>>(),
            Arc::new(data) as Arc<dyn Any + Send + Sync>,
        );
        Ok(self)
    }
=======
    ///
    /// Store a shared state value accessible to request extractors.
    ///
    /// The value can later be retrieved using [`SharedState<T>`]. Multiple
    /// calls may register different types.
    pub fn app_data<T>(mut self, state: T) -> Self
    where
        T: Send + Sync + 'static,
    {
        let data: SharedState<T> = state.into();
        self.app_data.insert(
            TypeId::of::<SharedState<T>>(),
            Arc::new(data) as Arc<dyn Any + Send + Sync>,
        );
        self
    }
>>>>>>> REPLACE

</suggested_fix>

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 thread src/app.rs Outdated
Copy link
Copy Markdown
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:83` </location>
<code_context>

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

+impl<T: Send + Sync> Clone for SharedState<T> {
</code_context>

<issue_to_address>
Manual Clone implementation is redundant with #[derive(Clone)].

Since Arc<T> already implements Clone, using #[derive(Clone)] is sufficient and avoids unnecessary manual code.
</issue_to_address>

### Comment 2
<location> `src/extractor.rs:131` </location>
<code_context>

+/// Errors that can occur when extracting built-in types.
+#[derive(Debug)]
+pub enum ExtractError {
+    /// No shared state of the requested type was found.
+    MissingState(&'static str),
</code_context>

<issue_to_address>
ExtractError is currently limited to MissingState; consider future extensibility.

Consider adding a non-exhaustive attribute or documentation to make it easier to add new error variants later.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
/// Errors that can occur when extracting built-in types.
#[derive(Debug)]
pub enum ExtractError {
=======
/// Errors that can occur when extracting built-in types.
///
/// Note: This enum is marked as non_exhaustive; more variants may be added in the future.
#[non_exhaustive]
#[derive(Debug)]
pub enum ExtractError {
>>>>>>> REPLACE

</suggested_fix>

### Comment 3
<location> `docs/rust-binary-router-library-design.md:807` </location>
<code_context>
+  Rust

-    ````rustrust
-    async fn handle_user_update(update: Message<UserUpdateData>) -> Result<()> {
-        // update.into_inner() gives UserUpdateData
-        //...
</code_context>

<issue_to_address>
The comment in this code example uses 'you', which should be avoided per the style guide.

The comment '// update.into_inner() gives UserUpdateData' uses 'you'. Consider rephrasing to avoid 2nd person, e.g., '// update.into_inner() returns the UserUpdateData instance'.
</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 thread src/extractor.rs
Comment thread src/extractor.rs
Comment thread docs/rust-binary-router-library-design.md
Copy link
Copy Markdown
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 - here's some feedback:

  • Consider keying app_data by TypeId::of::<T>() instead of TypeId::of::<SharedState<T>>() so that handlers can lookup SharedState<T> by the inner type directly and avoid confusion.
  • Since app_data() never fails, you could simplify its signature to return Self instead of Result<Self> for a cleaner builder chain.
  • Tests call MessageRequest::default() but MessageRequest doesn’t implement Default; either add a Default impl or update the tests to construct it explicitly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider keying `app_data` by `TypeId::of::<T>()` instead of `TypeId::of::<SharedState<T>>()` so that handlers can lookup `SharedState<T>` by the inner type directly and avoid confusion.
- Since `app_data()` never fails, you could simplify its signature to return `Self` instead of `Result<Self>` for a cleaner builder chain.
- Tests call `MessageRequest::default()` but `MessageRequest` doesn’t implement `Default`; either add a `Default` impl or update the tests to construct it explicitly.

## Individual Comments

### Comment 1
<location> `src/extractor.rs:85` </location>
<code_context>
-#[derive(Clone)]
 pub struct SharedState<T: Send + Sync>(Arc<T>);

+impl<T: Send + Sync> Clone for SharedState<T> {
+    fn clone(&self) -> Self { Self(self.0.clone()) }
+}
</code_context>

<issue_to_address>
Manual Clone implementation is redundant with #[derive(Clone)].

Deriving Clone is more concise and idiomatic here, as the manual implementation offers no additional benefit.
</issue_to_address>

### Comment 2
<location> `src/extractor.rs:130` </location>
<code_context>
 }

+/// Errors that can occur when extracting built-in types.
+#[derive(Debug)]
+pub enum ExtractError {
+    /// No shared state of the requested type was found.
</code_context>

<issue_to_address>
The attribute #[derive(Debug)] is placed before the doc comment; attributes should come after the doc comment.

Please move the doc comment above the #[derive(Debug)] attribute so that the doc comment comes first, followed by the attribute, as per the review instruction.
</issue_to_address>

### Comment 3
<location> `docs/rust-binary-router-library-design.md:807` </location>
<code_context>
+  Rust

-    ````rustrust
-    async fn handle_user_update(update: Message<UserUpdateData>) -> Result<()> {
-        // update.into_inner() gives UserUpdateData
-        //...
</code_context>

<issue_to_address>
The comment in this code example uses 'you', which should be avoided per the style guide.

The comment '// update.into_inner() gives UserUpdateData' uses 'you'. Please rephrase to avoid 2nd person, e.g., '// update.into_inner() returns a UserUpdateData instance'.
</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 thread src/extractor.rs Outdated
Comment thread src/extractor.rs
Comment thread docs/rust-binary-router-library-design.md
Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

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

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

Absence of Expected Change Pattern

  • wireframe/src/extractor.rs is usually changed with: wireframe/src/middleware.rs

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

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

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

Absence of Expected Change Pattern

  • wireframe/src/extractor.rs is usually changed with: wireframe/src/middleware.rs

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 19, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 19, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 19, 2025

@sourcery-ai review

Copy link
Copy Markdown
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:26` </location>
<code_context>
+    ///
+    /// Values are keyed by their [`TypeId`]. Registering additional
+    /// state of the same type will replace the previous entry.
+    pub app_data: HashMap<TypeId, Arc<dyn Any + Send + Sync>>,
+}
+
</code_context>

<issue_to_address>
HashMap<TypeId, ...> may cause issues with multiple types having the same TypeId in different crates.

Since TypeId is only unique within a crate, using it as a key can cause conflicts if the same type exists in multiple crates (e.g., due to re-exports or version mismatches). Consider this if the library is used across crate boundaries.

Suggested implementation:

```rust
    /// Shared state values registered with the application.
    ///
    /// Values are keyed by a unique string (such as a type name or user-provided key).
    /// Registering additional state with the same key will replace the previous entry.
    ///
    /// This avoids issues with `TypeId` not being globally unique across crates.
    pub app_data: HashMap<String, Arc<dyn Any + Send + Sync>>,

```

- All code that inserts or retrieves from `app_data` will need to use a `String` key (e.g., `std::any::type_name::<T>().to_string()` or a user-defined key) instead of `TypeId`.
- Update any helper methods or APIs that interact with `app_data` to accept/require a `String` key.
</issue_to_address>

### Comment 2
<location> `docs/rust-binary-router-library-design.md:812` </location>
<code_context>
-    }
+  ````rustrust
+  async fn handle_user_update(update: Message<UserUpdateData>) -> Result<()> {
+      // update.into_inner() returns a `UserUpdateData` instance
+      //...
+  }
</code_context>

<issue_to_address>
The comment uses 'you', which is a 2nd person pronoun, violating the instruction.

Please rephrase the comment to avoid using 'you'. For example: 'update.into_inner() returns a `UserUpdateData` instance.'
</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 thread src/extractor.rs
Comment thread docs/rust-binary-router-library-design.md
Copy link
Copy Markdown
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!


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
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

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

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

Absence of Expected Change Pattern

  • wireframe/src/extractor.rs is usually changed with: wireframe/src/middleware.rs

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

@leynos leynos merged commit 38c8f62 into main Jun 19, 2025
5 checks passed
@leynos leynos deleted the codex/add-shared-state-container-to-wireframeapp branch June 19, 2025 09:28
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