1#![doc = include_str!("readme.md")]
2
3use http::{Method, Uri, Version, header::HeaderMap};
4use std::fmt;
5
6#[derive(Debug)]
10pub enum ExtractorError {
11 PathRejection(String),
13
14 QueryRejection(String),
16
17 JsonRejection(String),
19
20 FormRejection(String),
22
23 ExtensionRejection(String),
25
26 HostRejection(String),
28
29 TypedHeaderRejection(String),
31
32 CookieRejection(String),
34
35 MultipartRejection(String),
37
38 WebSocketUpgradeRejection(String),
40
41 BytesRejection(String),
43
44 StreamRejection(String),
46
47 Custom(String),
49}
50
51impl fmt::Display for ExtractorError {
52 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53 match self {
54 ExtractorError::PathRejection(e) => write!(f, "Path extraction failed: {}", e),
55 ExtractorError::QueryRejection(e) => write!(f, "Query extraction failed: {}", e),
56 ExtractorError::JsonRejection(e) => write!(f, "Json extraction failed: {}", e),
57 ExtractorError::FormRejection(e) => write!(f, "Form extraction failed: {}", e),
58 ExtractorError::ExtensionRejection(e) => write!(f, "Extension extraction failed: {}", e),
59 ExtractorError::HostRejection(e) => write!(f, "Host extraction failed: {}", e),
60 ExtractorError::TypedHeaderRejection(e) => write!(f, "TypedHeader extraction failed: {}", e),
61 ExtractorError::CookieRejection(e) => write!(f, "Cookie extraction failed: {}", e),
62 ExtractorError::MultipartRejection(e) => write!(f, "Multipart extraction failed: {}", e),
63 ExtractorError::WebSocketUpgradeRejection(e) => write!(f, "WebSocketUpgrade extraction failed: {}", e),
64 ExtractorError::BytesRejection(e) => write!(f, "Bytes extraction failed: {}", e),
65 ExtractorError::StreamRejection(e) => write!(f, "Stream extraction failed: {}", e),
66 ExtractorError::Custom(msg) => write!(f, "Extractor error: {}", msg),
67 }
68 }
69}
70
71impl std::error::Error for ExtractorError {}
72
73#[derive(Debug, Clone)]
87pub struct Header<T>(pub T);
88
89pub type HttpMethod = Method;
93
94pub type RequestUri = Uri;
98
99pub type HttpVersion = Version;
103
104pub type Headers = HeaderMap;
108
109#[derive(Debug, Clone)]
111pub struct Extension<T>(pub T);
112
113#[derive(Debug, Clone, serde::Deserialize)]
115pub struct Form<T>(pub T);
116
117#[derive(Debug, Clone, serde::Deserialize)]
119pub struct Json<T>(pub T);
120
121#[derive(Debug, Clone)]
123pub struct Multipart;
124
125pub type OriginalUri = http::Uri;
127
128#[derive(Debug, Clone)]
130pub struct Path<T>(pub T);
131
132#[derive(Debug, Clone, serde::Deserialize)]
134pub struct Query<T>(pub T);
135
136#[derive(Debug, Clone)]
138pub struct State<T>(pub T);
139
140#[derive(Debug, Clone)]
142pub struct WebSocketUpgrade;
143
144pub use bytes::Bytes;
145
146pub type Stream = crate::Body;