1use super::*;
2
3macro_rules! define_codes {
4 (
5 $(
6 $(#[$meta:meta])*
7 code $name:ident => $status:expr;
8 )*
9 ) => {
10 $(
11 $(#[$meta])*
12 #[derive(Debug, Clone, Copy, Default)]
13 pub struct $name<T = ()>(pub T);
14
15 impl<T, R, S> From<$name<R>> for ErrorSet<S, T>
16 where
17 R: Into<S>,
18 T: Contains<$name>,
19 {
20 fn from(err: $name<R>) -> Self {
21 ErrorSet::new(err)
22 }
23 }
24
25 impl<T> StatusWrapper for $name<T> {
26 const STATUS_CODE: StatusCode = $status;
27
28 type Inner = T;
29 type Pure = $name;
30
31 fn into_inner(self) -> Self::Inner {
32 self.0
33 }
34 }
35 )*
36 };
37}
38
39define_codes!(
40 code BadRequest => StatusCode::BAD_REQUEST;
42
43 code Unauthorized => StatusCode::UNAUTHORIZED;
45
46 code PaymentRequired => StatusCode::PAYMENT_REQUIRED;
48
49 code Forbidden => StatusCode::FORBIDDEN;
51
52 code NotFound => StatusCode::NOT_FOUND;
54
55 code MethodNotAllowed => StatusCode::METHOD_NOT_ALLOWED;
57
58 code NotAcceptable => StatusCode::NOT_ACCEPTABLE;
60
61 code ProxyAuthenticationRequired => StatusCode::PROXY_AUTHENTICATION_REQUIRED;
63
64 code RequestTimeout => StatusCode::REQUEST_TIMEOUT;
66
67 code Conflict => StatusCode::CONFLICT;
69
70 code Gone => StatusCode::GONE;
72
73 code LengthRequired => StatusCode::LENGTH_REQUIRED;
75
76 code PreconditionFailed => StatusCode::PRECONDITION_FAILED;
78
79 code UriTooLong => StatusCode::URI_TOO_LONG;
84
85 code UnsupportedMediaType => StatusCode::UNSUPPORTED_MEDIA_TYPE;
87
88 code RangeNotSatisfiable => StatusCode::RANGE_NOT_SATISFIABLE;
90
91 code ExpectationFailed => StatusCode::EXPECTATION_FAILED;
93
94 code ImATeapot => StatusCode::IM_A_TEAPOT;
96
97 code MisdirectedRequest => StatusCode::MISDIRECTED_REQUEST;
99
100 code UnprocessableEntity => StatusCode::UNPROCESSABLE_ENTITY;
102
103 code Locked => StatusCode::LOCKED;
105
106 code FailedDependency => StatusCode::FAILED_DEPENDENCY;
108
109 code UpgradeRequired => StatusCode::UPGRADE_REQUIRED;
114
115 code PreconditionRequired => StatusCode::PRECONDITION_REQUIRED;
117
118 code TooManyRequests => StatusCode::TOO_MANY_REQUESTS;
120
121 code RequestHeaderFieldsTooLarge => StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE;
123
124 code UnavailableForLegalReasons => StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS;
126
127 code InternalServerError => StatusCode::INTERNAL_SERVER_ERROR;
129
130 code NotImplemented => StatusCode::NOT_IMPLEMENTED;
132
133 code BadGateway => StatusCode::BAD_GATEWAY;
135
136 code ServiceUnavailable => StatusCode::SERVICE_UNAVAILABLE;
138
139 code GatewayTimeout => StatusCode::GATEWAY_TIMEOUT;
141
142 code HttpVersionNotSupported => StatusCode::HTTP_VERSION_NOT_SUPPORTED;
144
145 code VariantAlsoNegotiates => StatusCode::VARIANT_ALSO_NEGOTIATES;
147
148 code InsufficientStorage => StatusCode::INSUFFICIENT_STORAGE;
150
151 code LoopDetected => StatusCode::LOOP_DETECTED;
153
154 code NotExtended => StatusCode::NOT_EXTENDED;
156
157 code NetworkAuthenticationRequired => StatusCode::NETWORK_AUTHENTICATION_REQUIRED;
159);