Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove UrlParamsMap and UrlParams #154

Merged
merged 1 commit into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `routing::EmptyRouterFuture` moved to `routing::future::EmptyRouterFuture` ([#133](/~https://github.com/tokio-rs/axum/pull/133))
- `routing::RouteFuture` moved to `routing::future::RouteFuture` ([#133](/~https://github.com/tokio-rs/axum/pull/133))
- `service::BoxResponseBodyFuture` moved to `service::future::BoxResponseBodyFuture` ([#133](/~https://github.com/tokio-rs/axum/pull/133))
- The following types no longer implement `Copy` ([#132](/~https://github.com/tokio-rs/axum/pull/132)):
- The following types no longer implement `Copy` ([#132](/~https://github.com/tokio-rs/axum/pull/132))
- `EmptyRouter`
- `ExtractorMiddleware`
- `ExtractorMiddlewareLayer`
- Replace `axum::body::BoxStdError` with `axum::Error`, which supports downcasting ([#150](/~https://github.com/tokio-rs/axum/pull/150))
- `WebSocket` now uses `axum::Error` as its error type ([#150](/~https://github.com/tokio-rs/axum/pull/150))
- `RequestParts` changes:
- `RequestParts` changes ([#153](/~https://github.com/tokio-rs/axum/pull/153))
- `method` new returns an `&http::Method`
- `method_mut` new returns an `&mut http::Method`
- `take_method` has been removed
- `uri` new returns an `&http::Uri`
- `uri_mut` new returns an `&mut http::Uri`
- `take_uri` has been removed
- These rejections have been removed as they're no longer used
- `MethodAlreadyExtracted`
- `UriAlreadyExtracted`
- `VersionAlreadyExtracted`
- `MethodAlreadyExtracted` ([#153](/~https://github.com/tokio-rs/axum/pull/153))
- `UriAlreadyExtracted` ([#153](/~https://github.com/tokio-rs/axum/pull/153))
- `VersionAlreadyExtracted` ([#153](/~https://github.com/tokio-rs/axum/pull/153))
- `UrlParamsRejection`
- `InvalidUrlParam`
- Removed `extract::UrlParams` and `extract::UrlParamsMap`. Use `extract::Path` instead

# 0.1.3 (06. August, 2021)

Expand Down
6 changes: 1 addition & 5 deletions src/extract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
//!
//! async fn handler(
//! // Extract captured parameters from the URL
//! params: extract::UrlParamsMap,
//! params: extract::Path<HashMap<String, String>>,
//! // Parse query string into a `HashMap`
//! query_params: extract::Query<HashMap<String, String>>,
//! // Buffer the request body into a `Bytes`
Expand Down Expand Up @@ -266,8 +266,6 @@ mod query;
mod raw_query;
mod request_parts;
mod tuple;
mod url_params;
mod url_params_map;

#[doc(inline)]
#[allow(deprecated)]
Expand All @@ -281,8 +279,6 @@ pub use self::{
query::Query,
raw_query::RawQuery,
request_parts::{Body, BodyStream},
url_params::UrlParams,
url_params_map::UrlParamsMap,
};
#[doc(no_inline)]
pub use crate::Json;
Expand Down
53 changes: 1 addition & 52 deletions src/extract/rejection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)]
Expand Down Expand Up @@ -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).
///
Expand Down
100 changes: 0 additions & 100 deletions src/extract/url_params.rs

This file was deleted.

69 changes: 0 additions & 69 deletions src/extract/url_params_map.rs

This file was deleted.

3 changes: 2 additions & 1 deletion src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,9 @@ where
///
/// ```
/// use axum::{routing::nest, prelude::*};
/// use std::collections::HashMap;
///
/// async fn users_get(params: extract::UrlParamsMap) {
/// async fn users_get(extract::Path(params): extract::Path<HashMap<String, String>>) {
/// // Both `version` and `id` were captured even though `users_api` only
/// // explicitly captures `id`.
/// let version = params.get("version");
Expand Down