| Crates.io | axum-option |
| lib.rs | axum-option |
| version | 0.1.0 |
| created_at | 2023-06-20 09:40:31.028459+00 |
| updated_at | 2023-06-20 09:40:31.028459+00 |
| description | Valid-or-missing extractor for Axum |
| homepage | |
| repository | |
| max_upload_size | |
| id | 894859 |
| size | 71,109 |
Better handling of optional extractors in axum.
This crate exposes a trait, and an extractor, that allows you to extract a potentially-missing value in your handlers.
Crates may implement FromRequestPartsOptional for their
extractors to signify that the extractor can have a missing value,
and then the ValidOption extractor can be used to extract
either a valid T, or a missing T, but reject an invalid T.
Option<T> directly?Unfortunately, axum's default 'Option' handler means either
'T passed validation' or 'T failed validation', essentially
meaning the same as Result<T, T::Rejection>.ok(), which
is typically not what you want to do. It means that supporting
handlers that, for example, need either a valid cookie, or
no cookie at all, requires per-crate newtype wrapper
boilerplate and knowledge over the internal workings of the
crate itself. ValidOption solves this M + N problem.
Now you can do ValidOption<Session> and get either a valid
session, or no session at all, but reject an invalid session.