{"record":{"id":"bd7adc550f950592","repo":"neon-bindings/neon","slug":"neon-export-can-only-be-applied-to-functions-consts-statics","errorCode":null,"errorMessage":"`neon::export` can only be applied to functions, consts, statics, and classes (impl blocks).","messagePattern":"`neon::export` can only be applied to functions, consts, statics, and classes \\(impl blocks\\)\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/neon-macros/src/export/mod.rs","lineNumber":57,"sourceCode":"        }\n\n        // Export a class (impl block)\n        syn::Item::Impl(item) => {\n            let meta = syn::parse_macro_input!(attr with class::meta::Parser);\n\n            class::export(meta, item)\n        }\n\n        // Return an error span for all other types\n        _ => unsupported(item),\n    }\n}\n\n// Generate an error for unsupported item types\nfn unsupported(item: syn::Item) -> proc_macro::TokenStream {\n    let span = syn::spanned::Spanned::span(&item);\n    let msg = \"`neon::export` can only be applied to functions, consts, statics, and classes (impl blocks).\";\n    let err = syn::Error::new(span, msg);\n\n    err.into_compile_error().into()\n}\n","sourceCodeStart":39,"sourceCodeEnd":61,"githubUrl":"https://github.com/neon-bindings/neon/blob/38960e4381d9ad13b551cdf2d261f609167c9bc2/crates/neon-macros/src/export/mod.rs#L39-L61","documentation":"The `#[neon::export]` attribute macro only supports a limited set of Rust items: functions, consts, statics, and classes (impl blocks). The `unsupported` function emits this compile error on any other item kind (e.g. modules, enums, type aliases, structs, traits).","triggerScenarios":"Writing `#[neon::export]` above a `mod`, `struct`, `enum`, `trait`, `type`, `use`, or `macro` item; the macro's `export` dispatcher matches the item type, fails all supported arms, and calls `unsupported` with the whole item.","commonSituations":"Trying to export a whole module or type at once; assuming the macro works like other export systems that accept types; copy-pasting the attribute onto the wrong item when adding native bindings.","solutions":["Move `#[neon::export]` onto an individual `fn`, `const`, `static`, or an `impl` block (class)","To export a struct, export an `impl` block for it instead of annotating the struct itself","Remove the attribute from unsupported items and export individual functions from within them"],"exampleFix":"// before\n#[neon::export]\nstruct Config { verbose: bool }\n// after\nstruct Config { verbose: bool }\n#[neon::export]\nimpl Config {\n    fn new() -> Self { Config { verbose: false } }\n}","handlingStrategy":"validation","validationCode":"// Rust-side habit: verify the annotated item kind\n// fn / const / static / impl are supported; struct, enum, mod, trait are not","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never put #[neon::export] on struct/enum/mod/trait/type items","Annotate the impl block for a class, not the struct declaration","Read the macro docs list of supported items before adding the attribute to unusual items"],"tags":["rust","neon","macros","export","unsupported-item"],"backgroundTag":"unsupported-operation","analyzedSha":"38960e4381d9ad13b551cdf2d261f609167c9bc2","analyzedAt":"2026-09-13T09:05:33.640Z","contentChangedAt":"2026-09-13T09:05:33.640Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}