Remove B type param (#1751)

Co-authored-by: Jonas Platte <[email protected]>
Co-authored-by: Michael Scofield <[email protected]>
This commit is contained in:
David Pedersen
2023-03-23 20:22:35 +01:00
co-authored by Jonas Platte Michael Scofield
parent f902f7470f
commit a4b7d3843c
99 changed files with 947 additions and 1142 deletions
+17 -21
View File
@@ -1,5 +1,4 @@
use axum::{
body::Body,
handler::Handler,
routing::{delete, get, on, post, MethodFilter, MethodRouter},
Router,
@@ -34,14 +33,13 @@ use axum::{
/// ```
#[derive(Debug)]
#[must_use]
pub struct Resource<S = (), B = Body> {
pub struct Resource<S = ()> {
pub(crate) name: String,
pub(crate) router: Router<S, B>,
pub(crate) router: Router<S>,
}
impl<S, B> Resource<S, B>
impl<S> Resource<S>
where
B: axum::body::HttpBody + Send + 'static,
S: Clone + Send + Sync + 'static,
{
/// Create a `Resource` with the given name.
@@ -57,7 +55,7 @@ where
/// Add a handler at `GET /{resource_name}`.
pub fn index<H, T>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
H: Handler<T, S>,
T: 'static,
{
let path = self.index_create_path();
@@ -67,7 +65,7 @@ where
/// Add a handler at `POST /{resource_name}`.
pub fn create<H, T>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
H: Handler<T, S>,
T: 'static,
{
let path = self.index_create_path();
@@ -77,7 +75,7 @@ where
/// Add a handler at `GET /{resource_name}/new`.
pub fn new<H, T>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
H: Handler<T, S>,
T: 'static,
{
let path = format!("/{}/new", self.name);
@@ -87,7 +85,7 @@ where
/// Add a handler at `GET /{resource_name}/:{resource_name}_id`.
pub fn show<H, T>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
H: Handler<T, S>,
T: 'static,
{
let path = self.show_update_destroy_path();
@@ -97,7 +95,7 @@ where
/// Add a handler at `GET /{resource_name}/:{resource_name}_id/edit`.
pub fn edit<H, T>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
H: Handler<T, S>,
T: 'static,
{
let path = format!("/{0}/:{0}_id/edit", self.name);
@@ -107,7 +105,7 @@ where
/// Add a handler at `PUT or PATCH /resource_name/:{resource_name}_id`.
pub fn update<H, T>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
H: Handler<T, S>,
T: 'static,
{
let path = self.show_update_destroy_path();
@@ -117,7 +115,7 @@ where
/// Add a handler at `DELETE /{resource_name}/:{resource_name}_id`.
pub fn destroy<H, T>(self, handler: H) -> Self
where
H: Handler<T, S, B>,
H: Handler<T, S>,
T: 'static,
{
let path = self.show_update_destroy_path();
@@ -132,14 +130,14 @@ where
format!("/{0}/:{0}_id", self.name)
}
fn route(mut self, path: &str, method_router: MethodRouter<S, B>) -> Self {
fn route(mut self, path: &str, method_router: MethodRouter<S>) -> Self {
self.router = self.router.route(path, method_router);
self
}
}
impl<S, B> From<Resource<S, B>> for Router<S, B> {
fn from(resource: Resource<S, B>) -> Self {
impl<S> From<Resource<S>> for Router<S> {
fn from(resource: Resource<S>) -> Self {
resource.router
}
}
@@ -148,9 +146,9 @@ impl<S, B> From<Resource<S, B>> for Router<S, B> {
mod tests {
#[allow(unused_imports)]
use super::*;
use axum::{extract::Path, http::Method, Router};
use axum::{body::Body, extract::Path, http::Method, Router};
use http::Request;
use tower::{Service, ServiceExt};
use tower::ServiceExt;
#[tokio::test]
async fn works() {
@@ -208,10 +206,8 @@ mod tests {
async fn call_route(app: &mut Router, method: Method, uri: &str) -> String {
let res = app
.ready()
.await
.unwrap()
.call(
.clone()
.oneshot(
Request::builder()
.method(method)
.uri(uri)