leptos-rs/leptos · error
`encoding` and `input` should not both be specified
Error message
`encoding` and `input` should not both be specified
What it means
The #[server] macro rejects specifying both `encoding` and `input` because they configure the same thing (how the request body is deserialized) through overlapping mechanisms: `encoding` picks a built-in encoding, while `input` gives a fully custom input type. Allowing both would be ambiguous, so the parser errors at compile time.
Source
Thrown at server_fn_macro/src/lib.rs:1113
} else if key == "encoding" {
if encoding.is_some() {
return Err(syn::Error::new(
key.span(),
"keyword argument repeated: `encoding`",
));
}
encoding = Some(stream.parse()?);
} else if key == "endpoint" {
if fn_path.is_some() {
return Err(syn::Error::new(
key.span(),
"keyword argument repeated: `endpoint`",
));
}
fn_path = Some(stream.parse()?);
} else if key == "input" {
if encoding.is_some() {
return Err(syn::Error::new(
key.span(),
"`encoding` and `input` should not both be \
specified",
));
} else if input.is_some() {
return Err(syn::Error::new(
key.span(),
"keyword argument repeated: `input`",
));
}
input = Some(stream.parse()?);
} else if key == "input_derive" {
if input_derive.is_some() {
return Err(syn::Error::new(
key.span(),
"keyword argument repeated: `input_derive`",
));
}View on GitHub (pinned to 32d20f6c9d)
Solutions
- Remove the `encoding = ...` argument and keep `input = ...` for a custom input type.
- Alternatively remove `input` and keep `encoding` to use a built-in encoding.
- Note the companion check: `output` is likewise mutually exclusive with `encoding`.
Example fix
// before
#[server(encoding = "Json", input = MyInput)]
async fn save(data: MyInput) -> Result<(), ServerFnError> { todo!() }
// after
#[server(input = MyInput)]
async fn save(data: MyInput) -> Result<(), ServerFnError> { todo!() } Defensive patterns
Strategy: validation
Validate before calling
// Reject attributes mixing `encoding` with `input`/`output`: // grep -rnE '#\[server\([^)\n]*encoding[^)\n]*(input|output)\s*=' src/ && exit 1 || exit 0
Prevention
- Remember the rule: `encoding` XOR (`input` and/or `output`).
- When migrating to custom types, delete the `encoding` key in the same change.
- Check library upgrade notes before porting old attribute signatures.
- Let cargo check fail loudly; never suppress macro errors with #[allow].
When it happens
Trigger: Writing #[server(encoding = "...", input = ...)] in the same attribute, e.g. mixing a legacy `encoding` arg with a newer `input` custom-type arg after a migration.
Common situations: Migrating from the older encoding API to custom input/output types and leaving the old `encoding` key in place; cargo expansions after upgrading server_fn versions; examples from docs that mix both styles.
Related errors
- `encoding` and `output` should not both be specified
- keyword argument repeated: `encoding`
- keyword argument repeated: `endpoint`
- keyword argument repeated: `input`
- keyword argument repeated: `output`
AI-assisted analysis of leptos-rs/leptos@32d20f6c9d (2026-09-01).
Data as JSON: /api/errors/694ca3ac3bf1833b.
Report an issue: GitHub.