Skip to content
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

Support #[derive(FromRequest)] on enums #1009

Merged
merged 7 commits into from
May 8, 2022
Merged

Support #[derive(FromRequest)] on enums #1009

merged 7 commits into from
May 8, 2022

Conversation

davidpdrsn
Copy link
Member

This adds support for #[derive(FromRequest)] on enums. It requires using #[from_request(via(OtherExtractor))] such as

#[derive(FromRequest, Clone)]
#[from_request(via(Extension))]
enum Env {
    Production,
    Development,
    Test,
}

A future improvement of this could be supporting something like

#[derive(FromRequest)]
enum Role {
    Admin(Admin),
    User(User),
    NotSignedIn,
}

Which would first attempt to extract Admin, then User, and finally fallback to Role::NotSignedIn. I might tackle that in the future :)

Fixes #997

@davidpdrsn davidpdrsn requested a review from jplatte May 8, 2022 13:10
@davidpdrsn davidpdrsn merged commit 852e548 into main May 8, 2022
@davidpdrsn davidpdrsn deleted the from-request-enum branch May 8, 2022 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make #[derive(FromRequest)] support enums
2 participants