tokio-rs/axum

Make Query extractor use Default impl for deserialization

Closed this issue · 2 comments

  • I have looked for existing issues (including closed) about this

Feature Request

Motivation

When using the Query extractor, it is already possible to use structs that have Option fields. However it is not possible to rely on the Default trait in case the whole struct (or parts thereof) is not present.

Proposal

Use the Default trait, when available, for structs extracted via Query, so that if fields are missing, those from the Default impl are used.

Alternatives

Continue wrapping every single field in Option, as it's possible now. This leads to much useless boilerplate.

This should work as it normally does with serde, so you can use #[serde(default)] attribute as anywhere else.

@mladedav you are right, I don't know how I haven't thought about that. Thanks.