Reorganize method routers for handlers and services (#405)

* Re-organize method routing for handlers

* Re-organize method routing for services

* changelog
This commit is contained in:
David Pedersen
2021-10-24 20:05:16 +00:00
committed by GitHub
parent 0ee7379d4f
commit 7692baf837
57 changed files with 743 additions and 742 deletions
+22 -15
View File
@@ -1,4 +1,4 @@
//! Routing between [`Service`]s.
//! Routing between [`Service`]s and handlers.
use self::future::{EmptyRouterFuture, NestedFuture, RouteFuture, RoutesFuture};
use crate::{
@@ -28,12 +28,19 @@ use tower_layer::Layer;
use tower_service::Service;
pub mod future;
pub mod handler_method_router;
pub mod service_method_router;
mod method_filter;
mod or;
pub use self::method_filter::MethodFilter;
#[doc(no_inline)]
pub use self::handler_method_router::{
any, connect, delete, get, head, on, options, patch, post, put, trace, MethodRouter,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
struct RouteId(u64);
@@ -109,7 +116,7 @@ where
/// # Example
///
/// ```rust
/// use axum::{handler::{get, delete}, Router};
/// use axum::{routing::{get, delete}, Router};
///
/// let app = Router::new()
/// .route("/", get(root))
@@ -136,7 +143,7 @@ where
/// Panics if the route overlaps with another route:
///
/// ```should_panic
/// use axum::{handler::get, Router};
/// use axum::{routing::get, Router};
///
/// let app = Router::new()
/// .route("/", get(|| async {}))
@@ -149,7 +156,7 @@ where
/// This also applies to `nest` which is similar to a wildcard route:
///
/// ```should_panic
/// use axum::{handler::get, Router};
/// use axum::{routing::get, Router};
///
/// let app = Router::new()
/// // this is similar to `/api/*`
@@ -164,7 +171,7 @@ where
/// Note that routes like `/:key` and `/foo` are considered overlapping:
///
/// ```should_panic
/// use axum::{handler::get, Router};
/// use axum::{routing::get, Router};
///
/// let app = Router::new()
/// .route("/foo", get(|| async {}))
@@ -204,7 +211,7 @@ where
///
/// ```
/// use axum::{
/// handler::get,
/// routing::get,
/// Router,
/// };
/// use http::Uri;
@@ -239,7 +246,7 @@ where
/// ```
/// use axum::{
/// extract::Path,
/// handler::get,
/// routing::get,
/// Router,
/// };
/// use std::collections::HashMap;
@@ -265,7 +272,7 @@ where
/// ```
/// use axum::{
/// Router,
/// service::get,
/// routing::service_method_router::get,
/// error_handling::HandleErrorExt,
/// http::StatusCode,
/// };
@@ -294,7 +301,7 @@ where
/// the prefix stripped.
///
/// ```rust
/// use axum::{handler::get, http::Uri, Router};
/// use axum::{routing::get, http::Uri, Router};
///
/// let app = Router::new()
/// .route("/foo/*rest", get(|uri: Uri| async {
@@ -366,7 +373,7 @@ where
///
/// ```rust
/// use axum::{
/// handler::get,
/// routing::get,
/// Router,
/// };
/// use tower::limit::{ConcurrencyLimitLayer, ConcurrencyLimit};
@@ -395,7 +402,7 @@ where
///
/// ```rust
/// use axum::{
/// handler::get,
/// routing::get,
/// Router,
/// };
/// use tower_http::trace::TraceLayer;
@@ -440,7 +447,7 @@ where
///
/// ```
/// use axum::{
/// handler::get,
/// routing::get,
/// Router,
/// };
///
@@ -470,7 +477,7 @@ where
/// ```
/// use axum::{
/// extract::ConnectInfo,
/// handler::get,
/// routing::get,
/// Router,
/// };
/// use std::net::SocketAddr;
@@ -496,7 +503,7 @@ where
/// ```
/// use axum::{
/// extract::connect_info::{ConnectInfo, Connected},
/// handler::get,
/// routing::get,
/// Router,
/// };
/// use hyper::server::conn::AddrStream;
@@ -555,7 +562,7 @@ where
///
/// ```
/// use axum::{
/// handler::get,
/// routing::get,
/// Router,
/// };
/// #