{"record":{"id":"ec43eceb4d7ddb01","repo":"leptos-rs/leptos","slug":"cannot-use-receiver-types-in-server-function-macro","errorCode":null,"errorMessage":"cannot use receiver types in server function macro","messagePattern":"cannot use receiver types in server function macro","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server_fn_macro/src/lib.rs","lineNumber":1270,"sourceCode":"                    builtin_encoding = true;\n                }\n                \"cbor\" => {\n                    input = Some(type_from_ident(syn::parse_quote!(Cbor)));\n                    output = Some(type_from_ident(syn::parse_quote!(Cbor)));\n                    builtin_encoding = true;\n                }\n                \"getcbor\" => {\n                    input = Some(type_from_ident(syn::parse_quote!(GetUrl)));\n                    output = Some(type_from_ident(syn::parse_quote!(Cbor)));\n                    builtin_encoding = true;\n                }\n                \"getjson\" => {\n                    input = Some(type_from_ident(syn::parse_quote!(GetUrl)));\n                    output = Some(syn::parse_quote!(Json));\n                    builtin_encoding = true;\n                }\n                _ => {\n                    return Err(syn::Error::new(\n                        encoding.span(),\n                        \"Encoding not found.\",\n                    ))\n                }\n            }\n        }\n\n        Ok(Self {\n            struct_name,\n            prefix,\n            input,\n            input_derive,\n            output,\n            fn_path,\n            builtin_encoding,\n            server,\n            client,\n            custom_wrapper,","sourceCodeStart":1252,"sourceCodeEnd":1288,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/server_fn_macro/src/lib.rs#L1252-L1288","documentation":"The #[server] macro only supports free functions (and generates a struct for them). If the annotated item is a method — i.e. its signature has a self receiver — codegen cannot produce a standalone server function struct, so the macro errors with this message.","triggerScenarios":"Annotating an impl-block method like `impl Api { #[server] async fn load(&self) ... }`; keeping a `&self`/`&mut self`/`self` parameter after adding #[server]; moving an existing method behind the macro during a refactor.","commonSituations":"Developers trying to expose existing service/trait methods as server functions instead of extracting them into free functions.","solutions":["Move the function out of the impl block and make it a free async function.","Replace the `self` receiver with explicit parameters (e.g. pass the needed fields as arguments).","Use #[server] only on associated-style free functions, calling the method internally if needed."],"exampleFix":"// before\nimpl Api {\n    #[server]\n    async fn load(&self, id: u32) -> Result<Item, ServerFnError> { self.fetch(id).await }\n}\n// after\n#[server]\nasync fn load(api: &Api, id: u32) -> Result<Item, ServerFnError> { api.fetch(id).await }","handlingStrategy":"validation","validationCode":"// Guard: never place #[server] on an impl method.\n// Verify before compiling by checking signatures lack a self receiver.\nfn assert_no_receiver(sig: &str) { assert!(!sig.contains(\"&self\") && !sig.contains(\"&mut self\") && !sig.contains(\"self:\"), \"#[server] cannot be used on methods\"); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only annotate free async fns, not impl methods","Extract method logic into free functions taking explicit params","Code-review macro attributes for receiver parameters"],"tags":["rust","proc-macro","receiver","unsupported-target"],"backgroundTag":"receiver-not-supported","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}