use super::*;
macro_rules! define_codes {
(
$(
$(#[$meta:meta])*
$(fn $fn_name:ident ();)?
code $name:ident => $status:expr;
)*
) => {
$(
$(#[$meta])*
#[derive(Debug, Clone, Copy, Default)]
pub struct $name<T = ()>(pub T);
impl<T> StatusProvider for $name<T> {
const STATUS_CODE: StatusCode = $status;
type Inner = T;
type WithInner<R> = $name<R>;
fn into_inner(self) -> Self::Inner {
self.0
}
}
impl<T, S> From<$name<T>> for ApiResponse<S>
where
S: Contains<$name<T>>,
$name<T>: StatusProvider<Inner: IntoResponse>,
{
fn from(err: $name<T>) -> Self {
ApiResponse::new(err)
}
}
impl<T> From<T> for $name<T> {
fn from(inner: T) -> Self {
Self(inner)
}
}
impl<T> std::ops::Deref for $name<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> std::ops::DerefMut for $name<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
)*
};
}
define_codes!(
fn map_bad_request();
code BadRequest => StatusCode::BAD_REQUEST;
fn map_unauthorized();
code Unauthorized => StatusCode::UNAUTHORIZED;
fn map_payment_required();
code PaymentRequired => StatusCode::PAYMENT_REQUIRED;
fn map_forbidden();
code Forbidden => StatusCode::FORBIDDEN;
fn map_not_found();
code NotFound => StatusCode::NOT_FOUND;
fn map_method_not_allowed();
code MethodNotAllowed => StatusCode::METHOD_NOT_ALLOWED;
fn map_not_acceptable();
code NotAcceptable => StatusCode::NOT_ACCEPTABLE;
fn map_proxy_authentication_required();
code ProxyAuthenticationRequired => StatusCode::PROXY_AUTHENTICATION_REQUIRED;
fn map_request_timeout();
code RequestTimeout => StatusCode::REQUEST_TIMEOUT;
fn map_conflict();
code Conflict => StatusCode::CONFLICT;
fn map_gone();
code Gone => StatusCode::GONE;
fn map_length_required();
code LengthRequired => StatusCode::LENGTH_REQUIRED;
fn map_precondition_failed();
code PreconditionFailed => StatusCode::PRECONDITION_FAILED;
fn map_payload_too_large();
code PayloadTooLarge => StatusCode::PAYLOAD_TOO_LARGE;
fn map_uri_too_long();
code UriTooLong => StatusCode::URI_TOO_LONG;
fn map_unsupported_media_type();
code UnsupportedMediaType => StatusCode::UNSUPPORTED_MEDIA_TYPE;
fn map_range_not_satisfiable();
code RangeNotSatisfiable => StatusCode::RANGE_NOT_SATISFIABLE;
fn map_expectation_failed();
code ExpectationFailed => StatusCode::EXPECTATION_FAILED;
fn map_im_a_teapot();
code ImATeapot => StatusCode::IM_A_TEAPOT;
fn map_misdirected_request();
code MisdirectedRequest => StatusCode::MISDIRECTED_REQUEST;
fn map_unprocessable_entity();
code UnprocessableEntity => StatusCode::UNPROCESSABLE_ENTITY;
fn map_locked();
code Locked => StatusCode::LOCKED;
fn map_failed_dependency();
code FailedDependency => StatusCode::FAILED_DEPENDENCY;
fn map_too_early();
code TooEarly => StatusCode::TOO_EARLY;
fn map_upgrade_required();
code UpgradeRequired => StatusCode::UPGRADE_REQUIRED;
fn map_precondition_required();
code PreconditionRequired => StatusCode::PRECONDITION_REQUIRED;
fn map_too_many_requests();
code TooManyRequests => StatusCode::TOO_MANY_REQUESTS;
fn map_request_header_fields_too_large();
code RequestHeaderFieldsTooLarge => StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE;
fn map_unavailable_for_legal_reasons();
code UnavailableForLegalReasons => StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS;
fn map_internal();
code Internal => StatusCode::INTERNAL_SERVER_ERROR;
fn map_not_implemented();
code NotImplemented => StatusCode::NOT_IMPLEMENTED;
fn map_bad_gateway();
code BadGateway => StatusCode::BAD_GATEWAY;
fn map_service_unavailable();
code ServiceUnavailable => StatusCode::SERVICE_UNAVAILABLE;
fn map_gateway_timeout();
code GatewayTimeout => StatusCode::GATEWAY_TIMEOUT;
fn map_http_version_not_supported();
code HttpVersionNotSupported => StatusCode::HTTP_VERSION_NOT_SUPPORTED;
fn map_variant_also_negotiates();
code VariantAlsoNegotiates => StatusCode::VARIANT_ALSO_NEGOTIATES;
fn map_insufficient_storage();
code InsufficientStorage => StatusCode::INSUFFICIENT_STORAGE;
fn map_loop_detected();
code LoopDetected => StatusCode::LOOP_DETECTED;
fn map_not_extended();
code NotExtended => StatusCode::NOT_EXTENDED;
fn map_network_authentication_required();
code NetworkAuthenticationRequired => StatusCode::NETWORK_AUTHENTICATION_REQUIRED;
);