DioxusLabs/dioxus · error · syn::Error
Store macro does not support unions
Error message
Store macro does not support unions
What it means
The #[derive(Store)] macro from dioxus-signals (stores-macro) only implements Store for structs and enums. Rust unions have no field-access discipline the field-tracking store machinery can hook, so the derive refuses unions outright.
Source
Thrown at packages/stores-macro/src/derive.rs:64
let mut extension_generics = generics.clone();
extension_generics.params.insert(0, parse_quote!(__Lens));
match &input.data {
syn::Data::Struct(data_struct) => derive_store_struct(
&input,
data_struct,
extension_trait_name,
transposed_name,
extension_generics,
),
syn::Data::Enum(data_enum) => derive_store_enum(
&input,
data_enum,
extension_trait_name,
transposed_name,
extension_generics,
),
syn::Data::Union(_) => Err(syn::Error::new(
input.span(),
"Store macro does not support unions",
)),
}
}
/// Build a constructor expression: `prefix { a, b }`, `prefix(a, b)`, or just `prefix`.
fn construct_from_fields(prefix: TokenStream2, fields: &Fields, names: &[Ident]) -> TokenStream2 {
match fields {
Fields::Named(_) => quote! { #prefix { #(#names),* } },
Fields::Unnamed(_) => quote! { #prefix(#(#names),*) },
Fields::Unit => quote! { #prefix },
}
}
/// Zip original fields with their transposed store types, preserving visibility and names.
fn zip_transposed_fields(fields: &Fields, types: &[TokenStream2]) -> Vec<TokenStream2> {
match fields {View on GitHub (pinned to 393d190a80)
Solutions
- Convert the union to an enum or struct (e.g. a tagged enum) and derive Store on that
- Wrap the union in a struct, derive Store on the wrapper, and expose union fields through methods
- Drop the derive from the union and manage that state without Store
Example fix
// before
#[derive(Store)]
union Packet { raw: u32, fields: Parts }
// after
struct Packet { raw: PacketRepr }
#[derive(Store)]
struct AppState { packet: Packet } Defensive patterns
Strategy: validation
Prevention
- Derive Store only on structs and enums; grep for `union` in files carrying the derive
- Model unions as tagged enums or struct wrappers when state must live in a Store
- Don't blanket-apply dioxus derives with editor snippets across a module
When it happens
Trigger: Annotating any `union U { a: u32, b: f32 }` declaration with #[derive(Store)].
Common situations: FFI/bit-pattern types declared as unions accidentally receiving the derive via a blanket copy-paste; bringing dioxus into an existing crate that models raw memory with unions.
Related errors
- Use `api_route` instead of `route` to use OpenAPI options
- path parameter `{}` not found in function arguments
- query parameter `{}` not found in function arguments
- Cannot have multiple query parameters when one is a catch-al
- HTTP method specified both in macro and in attribute
AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16).
Data as JSON: /api/errors/478a064c2ad79781.
Report an issue: GitHub.