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

Add helper methods to run easily run extractors #1297

Closed
davidpdrsn opened this issue Aug 22, 2022 · 1 comment · Fixed by #1301
Closed

Add helper methods to run easily run extractors #1297

davidpdrsn opened this issue Aug 22, 2022 · 1 comment · Fixed by #1301
Assignees
Labels
A-axum C-feature-request Category: A feature request, i.e: not implemented / a PR.
Milestone

Comments

@davidpdrsn
Copy link
Member

In axum 0.5 you could call request_parts.extract::<T>() which is a bit nicer than T::from_request(request_parts) but #1272 removed the RequestParts type and thus also this method.

For 0.6 we should think about adding back something similar.

Haven't thought much about it but perhaps something like

pub trait RequestExt {
    async fn extract<T>(self) -> Result<(Self, T), T::Rejection>
    where
        T: FromRequest,
    {
        ...
    }
}

pub trait PartsExt {
    async fn extract<T>(&mut self) -> Result<T, T::Rejection>
    where
        T: FromRequestParts,
    {
        ...
    }
}

Should also think about how to pass state and whether we need separate methods for when the state is and isn't ().

@davidpdrsn davidpdrsn added C-feature-request Category: A feature request, i.e: not implemented / a PR. A-axum labels Aug 22, 2022
@davidpdrsn davidpdrsn added this to the 0.6 milestone Aug 22, 2022
@jplatte
Copy link
Member

jplatte commented Aug 22, 2022

We should also have extract_parts in RequestExt, so users don't need to do into_parts + from_parts themselves. Although calling that multiple times consecutively might be slower than doing one into_parts + from_parts and using .extract on the Parts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-axum C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants