{"record":{"id":"81324a790aede998","repo":"vectordotdev/vector","slug":"required-one-of-is-not-supported-on-newtype-stru","errorCode":null,"errorMessage":"`required_one_of` is not supported on newtype struct fields","messagePattern":"`required_one_of` is not supported on newtype struct fields","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"lib/vector-config-macros/src/configurable.rs","lineNumber":554,"sourceCode":"        // Don't map this field if it's marked to be skipped for both serialization and deserialization.\n        .filter(|field| field.visible())\n        .map(generate_tuple_struct_field);\n\n    quote! {\n        fn generate_schema(schema_gen: &::std::cell::RefCell<::vector_config::schema::SchemaGenerator>) -> std::result::Result<::vector_config::schema::SchemaObject, ::vector_config::GenerateError> {\n            let mut subschemas = ::std::collections::Vec::new();\n\n            #(#mapped_fields)*\n\n            Ok(::vector_config::schema::generate_tuple_schema(&subschemas))\n        }\n    }\n}\n\nfn build_newtype_struct_generate_schema_fn(fields: &[Field<'_>]) -> proc_macro2::TokenStream {\n    for field in fields.iter() {\n        if field.required_one_of().is_some() {\n            return syn::Error::new(\n                field.span(),\n                \"`required_one_of` is not supported on newtype struct fields\",\n            )\n            .to_compile_error();\n        }\n    }\n\n    // Map the fields normally, but we should end up with a single field at the end.\n    let mut mapped_fields = fields\n        .iter()\n        // Don't map this field if it's marked to be skipped for both serialization and deserialization.\n        .filter(|field| field.visible())\n        .map(generate_struct_field)\n        .collect::<Vec<_>>();\n\n    if mapped_fields.len() != 1 {\n        panic!(\"newtype structs should never have more than one field\");\n    }","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-config-macros/src/configurable.rs#L536-L572","documentation":"Compile-time error from `build_newtype_struct_generate_schema_fn`. A newtype struct (`struct Wrapper(T)`) is transparent in serde — it serializes as the inner value directly, with no object key for the single field — so `required_one_of`, which keys on field names, cannot apply. The macro rejects it before generating the schema function.","triggerScenarios":"`#[derive(Configurable)]` on a newtype struct whose single field has `#[configurable(required_one_of(...))]`.","commonSituations":"Wrapping an existing config type in a newtype (e.g. for the newtype pattern or type safety) while keeping attributes that only make sense on named-struct fields.","solutions":["Remove the `required_one_of` attribute from the newtype field","Or change the wrapper to a named struct with one named, optional field and put the group there"],"exampleFix":"// before\nstruct Wrapper(#[configurable(required_one_of = [\"x\"])] Inner);\n\n// after\nstruct Wrapper {\n    #[configurable(required_one_of = [\"x\", \"y\"])]\n    inner: Option<Inner>,\n}","handlingStrategy":"validation","validationCode":"# CI gate: unsupported newtype usage fails at compile time\ncargo check --workspace --all-targets","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Newtype wrappers are transparent in serde — no field keys, no name-keyed constraints","Move the constraint to a named struct inside the wrapper if needed"],"tags":["rust","proc-macro","compile-time","newtype","schema-validation","vector"],"backgroundTag":"macro-attribute-misplaced","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}