1#![doc = include_str!("readme.md")]
2
3use axum::{
4 body::Body,
5 extract::rejection::*,
6 http::{Method, Uri, Version, header::HeaderMap},
7};
8use std::fmt;
9
10pub use axum::extract::{Extension, Form, Path, Query, State};
11
12pub use axum::Json;
13
14#[derive(Debug)]
18pub enum ExtractorError {
19 PathRejection(PathRejection),
21
22 QueryRejection(QueryRejection),
24
25 JsonRejection(JsonRejection),
27
28 FormRejection(FormRejection),
30
31 ExtensionRejection(ExtensionRejection),
33
34 Custom(String),
36}
37
38impl fmt::Display for ExtractorError {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 ExtractorError::PathRejection(e) => write!(f, "Path extraction failed: {}", e),
42 ExtractorError::QueryRejection(e) => write!(f, "Query extraction failed: {}", e),
43 ExtractorError::JsonRejection(e) => write!(f, "Json extraction failed: {}", e),
44 ExtractorError::FormRejection(e) => write!(f, "Form extraction failed: {}", e),
45 ExtractorError::ExtensionRejection(e) => write!(f, "Extension extraction failed: {}", e),
46 ExtractorError::Custom(msg) => write!(f, "Extractor error: {}", msg),
47 }
48 }
49}
50
51impl std::error::Error for ExtractorError {}
52
53impl From<PathRejection> for ExtractorError {
54 fn from(e: PathRejection) -> Self {
55 ExtractorError::PathRejection(e)
56 }
57}
58
59impl From<QueryRejection> for ExtractorError {
60 fn from(e: QueryRejection) -> Self {
61 ExtractorError::QueryRejection(e)
62 }
63}
64
65impl From<JsonRejection> for ExtractorError {
66 fn from(e: JsonRejection) -> Self {
67 ExtractorError::JsonRejection(e)
68 }
69}
70
71impl From<FormRejection> for ExtractorError {
72 fn from(e: FormRejection) -> Self {
73 ExtractorError::FormRejection(e)
74 }
75}
76
77impl From<ExtensionRejection> for ExtractorError {
78 fn from(e: ExtensionRejection) -> Self {
79 ExtractorError::ExtensionRejection(e)
80 }
81}
82
83#[derive(Debug, Clone)]
97pub struct Header<T>(pub T);
98
99pub type RawBody = Body;
103
104pub type HttpMethod = Method;
108
109pub type RequestUri = Uri;
113
114pub type HttpVersion = Version;
118
119pub type Headers = HeaderMap;