mirror of
https://github.com/tokio-rs/axum.git
synced 2025-03-01 06:46:48 +01:00
* initial working impl * support `#[from_request(via(...))]` * support extracting the whole thing at once * rely on type inference * fix footgun * fix typo * generate rejection enums * move tests to trybuild * minor clean up * docs * Support multiple generic extractors with same "via" type * support `Result` as well * Update axum-macros/src/from_request.rs Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com> * Add `#[automatically_derived]` * remove needless `#[derive(Debug)]` on macro types * Fix error messages that different for some reason * Update axum-macros/src/lib.rs Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com> * add more `#[automatically_derived]` * support same types in tuple structs * update docs * prep axum-macros for release * address review feedback * Update axum-macros/src/lib.rs Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com> * Update axum-macros/src/lib.rs Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com> * Update known limitation Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
58 lines
1.5 KiB
Rust
58 lines
1.5 KiB
Rust
use axum::{
|
|
body::Body,
|
|
extract::{
|
|
rejection::{ExtensionRejection, TypedHeaderRejection},
|
|
Extension, FromRequest, TypedHeader,
|
|
},
|
|
headers::{self, UserAgent},
|
|
};
|
|
use axum_macros::FromRequest;
|
|
use std::convert::Infallible;
|
|
|
|
#[derive(FromRequest)]
|
|
struct Extractor {
|
|
#[from_request(via(Extension))]
|
|
state: State,
|
|
#[from_request(via(TypedHeader))]
|
|
user_agent: UserAgent,
|
|
#[from_request(via(TypedHeader))]
|
|
content_type: headers::ContentType,
|
|
#[from_request(via(TypedHeader))]
|
|
etag: Option<headers::ETag>,
|
|
#[from_request(via(TypedHeader))]
|
|
host: Result<headers::Host, TypedHeaderRejection>,
|
|
}
|
|
|
|
fn assert_from_request()
|
|
where
|
|
Extractor: FromRequest<Body, Rejection = ExtractorRejection>,
|
|
{
|
|
}
|
|
|
|
fn assert_rejection(rejection: ExtractorRejection)
|
|
where
|
|
ExtractorRejection: std::fmt::Debug + std::fmt::Display + std::error::Error,
|
|
{
|
|
match rejection {
|
|
ExtractorRejection::State(inner) => {
|
|
let _: ExtensionRejection = inner;
|
|
}
|
|
ExtractorRejection::UserAgent(inner) => {
|
|
let _: TypedHeaderRejection = inner;
|
|
}
|
|
ExtractorRejection::ContentType(inner) => {
|
|
let _: TypedHeaderRejection = inner;
|
|
}
|
|
ExtractorRejection::Etag(inner) => {
|
|
let _: Infallible = inner;
|
|
}
|
|
ExtractorRejection::Host(inner) => {
|
|
let _: Infallible = inner;
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
struct State;
|
|
|
|
fn main() {}
|