{"record":{"id":"f56b5392e2b4c041","repo":"quickwit-oss/quickwit","slug":"serde-multikey-was-applied-to-a-non-serialize-de","errorCode":null,"errorMessage":"`serde_multikey` was applied to a non Serialize/Deserialize struct","messagePattern":"`serde_multikey` was applied to a non Serialize/Deserialize struct","errorType":"exception","errorClass":"proc-macro compile error","httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-macros/src/lib.rs","lineNumber":61,"sourceCode":"    let main_struct = generate_main_struct(input.clone())?;\n\n    let proxy_struct = generate_proxy_struct(input)?;\n\n    Ok(quote!(\n    #main_struct\n    #proxy_struct\n    )\n    .into())\n}\n\n/// Generate the main struct. It's a copy of the original struct, but with most\n/// ser/de attributes removed, and serde try_from/into `__MultiKey{}` added.\nfn generate_main_struct(mut input: ItemStruct) -> Result<TokenStream2, Error> {\n    let (serialize, deserialize) = get_ser_de(&input.attrs)?;\n    let has_utoipa_schema = get_and_remove_utoipa_schema(&mut input.attrs)?;\n\n    if !deserialize && !serialize {\n        return Err(Error::new(\n            Span::call_site(),\n            \"`serde_multikey` was applied to a non Serialize/Deserialize struct\",\n        ));\n    }\n\n    // remove serde and utoipa attributes from fields\n    for field in input.fields.iter_mut() {\n        let attrs = mem::take(&mut field.attrs);\n        field.attrs = attrs\n            .into_iter()\n            .filter(|attr| {\n                !(attr.path().is_ident(\"serde_multikey\")\n                    || attr.path().is_ident(\"serde\")\n                    || attr.path().is_ident(\"serde_as\")\n                    || attr.path().is_ident(\"schema\"))\n            })\n            .collect();\n    }","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-macros/src/lib.rs#L43-L79","documentation":"generate_main_struct inspects the struct's remaining attributes to determine whether it derives serde Serialize and/or Deserialize (get_ser_de). serde_multikey's generated code relies on serde try_from/into plumbing, so if the struct has neither Serialize nor Deserialize configured, the macro rejects it with this compile error.","triggerScenarios":"Annotating a plain struct with #[serde_multikey(...)] when the struct lacks both #[derive(Serialize)] / #[derive(Deserialize)] (or equivalent serde derive attributes).","commonSituations":"Adding serde_multikey to an internal struct that was never serde-annotated; forgetting the serde derive import (`use serde::{Serialize, Deserialize};`) so the derive attribute is absent.","solutions":["Add #[derive(Serialize, Deserialize)] (or at least the one you need) to the struct alongside #[serde_multikey].","Ensure `serde` is a dependency with the `derive` feature and that the derives are imported."],"exampleFix":"// before\n#[serde_multikey(fields(id))]\nstruct MultiKey { id: String, name: String }\n// after\n#[derive(Serialize, Deserialize)]\n#[serde_multikey(fields(id))]\nstruct MultiKey { id: String, name: String }","handlingStrategy":"validation","validationCode":"// Ensure the struct carries serde derives before applying serde_multikey:\n#[derive(Serialize, Deserialize)]\n#[serde_multikey(fields(key))]\nstruct MyKey { key: String }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair #[serde_multikey] with #[derive(Serialize, Deserialize)]","Import the derives: use serde::{Serialize, Deserialize};","Keep serde with the `derive` feature enabled in Cargo.toml"],"tags":["rust","proc-macro","serde","compile-time"],"backgroundTag":"missing-dependency","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}