tokio-rs / axum

Ergonomic and modular web framework built with Tokio, Tower, and Hyper
18.85k stars 1.05k forks source link

Make extractors with Infallible rejection type more convenient #2249

Open jplatte opened 1 year ago

jplatte commented 1 year ago

Feature Request

Motivation

Some extractors such as CookieJar use an Infallible rejection type. Currently, one has to use .unwrap() / .expect("infallible") / .unwrap_or_else(|i| match i {}) after the actual extraction function call to get rid of it.

Proposal

Alternatives

Open questions

Are body extractors ever infallible / does it make sense to provide RequestExt::extract_infallible?

mladedav commented 5 months ago

Are body extractors ever infallible / does it make sense to provide RequestExt::extract_infallible?

Body itself is infallible as it pretty much just provides the underlying stream. Anything that actually collects the bytes would be fallible though. I don't think it makes much sense to add extract_infallible for that case though.

But it does make sense to me for request parts.

ItsEthra commented 2 days ago

I think this can be closed now since in the 1.82 you can just match the result with infallible https://blog.rust-lang.org/2024/10/17/Rust-1.82.0.html#omitting-empty-types-in-pattern-matching.