Skip to content

Is the Optional extractor no longer compatible with Common extractors? #3136

Closed Answered by Turbo87
baby195lxl asked this question in Q&A
Discussion options

You must be logged in to vote
#[derive(Deserialize)]
struct Pagination {
    #[serde(default = "1")]
    page: usize,
    #[serde(default = "30")]
    per_page: usize,
}

async fn get_user_things(
    Path(user_id): Path<Uuid>,
    Query(pagination): Query<Pagination>,
) {
    // ...
}

something like this is roughly what you want. alternatively, you can use Option<usize> inside the struct and remove the #[serde(default)] annotations.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Turbo87
Comment options

Turbo87 Jan 2, 2025
Collaborator

@jplatte
Comment options

Answer selected by baby195lxl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants