pub fn empty_as_none<'de, D, T>(de: D) -> Result<Option<T>, D::Error>Expand description
Deserialize an optional query parameter, treating an empty value as absent.
?root= is what a client sends when it builds a URL from a template
and the value happens to be unset — ?root=&depth=&locale= is an
entirely ordinary request. Plain Option<i64> rejects it with
400 cannot parse integer from empty string, which is both wrong and
hostile: the parameter is optional, and omitting its value is the
clearest way to say so.
A non-empty value that still doesn’t parse remains a 400 — that is a
genuine client error, and silently coercing ?depth=abc to the
default would hide it.
§Errors
Propagates the underlying parse failure for non-empty values.