-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing OptionalFromRequestParts
implementation for the Host
extractor from the axum-extra crate
#3170
Comments
Host
extractor to the axum-extra crate, we've lost the OptionalFromRequestParts
implementation for itOptionalFromRequestParts
implementation for the Host
extractor from the axum-extra crate
The |
Specifically I meant the one from axum but axum_extra seems to have one too that is also affected. |
I see, so in case someone comes across this |
@taladar |
Semantically 99% of the time when I even want several query parameters stored in the same value I want to know if all of them have been specified though, not a mess of several |
Could you give an example? I have the exact opposite experience, I have never seen a set of query parameters that are optional as a group, rather than individually. |
@dnlsndr Want to send a PR for |
Usually that occurs when you have related information that is useless if you only have some of it, e.g. you have a map API with x, y and z parameters or a sort by and sort direction parameter. |
I'd be happy to! PR incoming. |
let (x, y, z) = match (x, y, z) {
(Some(x), Some(y), Some(z)) => (x, y, z),
_ => return Err(...),
} I think something like this should work?
you can use |
That is the kind of code that I would consider "manually checking". Obviously it is not impossible but there definitely is a use-case for not having that check inside the handler. |
I haven't tried it, but another alternative could be to use something like this if you always need these params to be present together: struct QueryParams {
#[serde(flatten)]
xyz: Option<XYZ>
}
struct XYZ {
x: f32,
y: f32,
z: f32,
} |
yet another alternative: you can use |
That last one does sound like an interesting option. In any case it would probably be useful to have something that works similar to Option mentioned in the docs somewhere. |
@taladar I just stumbled across this in the source code: This seems to be doing what you want, dunno why it's separated out into a different extractor though. It's in the axum-extrac crate under the |
Yes, that is the one I found too and that @Turbo87 said would soon be deprecated. |
Bug Report
Version
v0.8.1
Platform
UNIX
Crates
axum
axum-extra
Description
Now that the
Host
extractor was moved to the axum-extra crate and with the new changes to how Option extractors work, it's not possible to do something like this anymore:as the compiler complains with this error:
The text was updated successfully, but these errors were encountered: