Remove UrlParamsMap and UrlParams (#154)

Use `extract::Path` instead.
This commit is contained in:
David Pedersen
2021-08-07 21:22:08 +02:00
committed by GitHub
parent 6a82dd75ea
commit a6b3e09827
6 changed files with 12 additions and 232 deletions
+1 -52
View File
@@ -82,9 +82,7 @@ define_rejection! {
define_rejection! {
#[status = INTERNAL_SERVER_ERROR]
#[body = "No url params found for matched route. This is a bug in axum. Please open an issue"]
/// Rejection type for [`UrlParamsMap`](super::UrlParamsMap) and
/// [`UrlParams`](super::UrlParams) if you try and extract the URL params
/// more than once.
/// Rejection type used if you try and extract the URL params more than once.
pub struct MissingRouteParams;
}
@@ -110,44 +108,6 @@ define_rejection! {
pub struct InvalidFormContentType;
}
/// Rejection type for [`UrlParams`](super::UrlParams) if the capture route
/// param didn't have the expected type.
#[derive(Debug)]
pub struct InvalidUrlParam {
type_name: &'static str,
}
impl InvalidUrlParam {
pub(super) fn new<T>() -> Self {
InvalidUrlParam {
type_name: std::any::type_name::<T>(),
}
}
}
impl std::fmt::Display for InvalidUrlParam {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Invalid URL param. Expected something of type `{}`",
self.type_name
)
}
}
impl std::error::Error for InvalidUrlParam {}
impl IntoResponse for InvalidUrlParam {
type Body = Full<Bytes>;
type BodyError = Infallible;
fn into_response(self) -> http::Response<Self::Body> {
let mut res = http::Response::new(Full::from(self.to_string()));
*res.status_mut() = http::StatusCode::BAD_REQUEST;
res
}
}
/// Rejection type for [`Path`](super::Path) if the capture route
/// param didn't have the expected type.
#[derive(Debug)]
@@ -269,17 +229,6 @@ composite_rejection! {
}
}
composite_rejection! {
/// Rejection used for [`UrlParams`](super::UrlParams).
///
/// Contains one variant for each way the [`UrlParams`](super::UrlParams) extractor
/// can fail.
pub enum UrlParamsRejection {
InvalidUrlParam,
MissingRouteParams,
}
}
composite_rejection! {
/// Rejection used for [`Path`](super::Path).
///