Skip to content

Conversation

@ealmloff
Copy link
Member

The transpose operation on stores pushes the reactivity one layer deeper into the type. For example, transposing Store<Result<T, E>> gives you Result<Store<T>, Store<E>>.

The store macro creates a transposed version of every type with the fields replaced with their store variants. For types similar to Result and Option with only generic fields, the transposed version of the type is more difficult to name during matching.

This PR adjusts the macro logic to only emit a type alias all fields of the item we are deriving store on are generic. This makes it possible to match on the transposed version of the item as normal:

#[derive(Store)]
#[non_exhaustive]
enum Enum<T> {
    Foo,
    Bar(T),
}

let store = use_store(|| Enum::Bar("Hello".to_string()));

let transposed = store.transpose();
use Enum::*;
match transposed {
    Enum::Foo => {}
    Bar(bar) => {
        let bar: String = bar();
    }
}

@ealmloff ealmloff requested a review from a team as a code owner October 24, 2025 14:36
@ealmloff ealmloff added enhancement New feature or request breaking This is a breaking change stores labels Oct 24, 2025
@ealmloff ealmloff mentioned this pull request Oct 27, 2025
5 tasks
@jkelleyrtp jkelleyrtp merged commit 9b52aa6 into DioxusLabs:main Oct 27, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking This is a breaking change enhancement New feature or request stores

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants