Remove B type param: Follow ups (#1789)

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:24:58 +01:00
co-authored by Jonas Platte Michael Scofield
parent 0d50d17304
commit 2ae0cdf7cf
70 changed files with 428 additions and 527 deletions
-1
View File
@@ -22,7 +22,6 @@ use std::ops::{Deref, DerefMut};
/// use axum::{
/// async_trait,
/// extract::FromRequestParts,
/// body::BoxBody,
/// response::{IntoResponse, Response},
/// http::{StatusCode, request::Parts},
/// };
+3 -4
View File
@@ -1,11 +1,10 @@
use axum::{
async_trait,
body::Body,
extract::{rejection::RawFormRejection, FromRequest, RawForm},
extract::{rejection::RawFormRejection, FromRequest, RawForm, Request},
response::{IntoResponse, Response},
Error, RequestExt,
};
use http::{Request, StatusCode};
use http::StatusCode;
use serde::de::DeserializeOwned;
use std::{fmt, ops::Deref};
@@ -59,7 +58,7 @@ where
{
type Rejection = FormRejection;
async fn from_request(req: Request<Body>, _state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection> {
let RawForm(bytes) = req
.extract()
.await
+3 -4
View File
@@ -1,9 +1,7 @@
use axum::async_trait;
use axum::body::Body;
use axum::extract::{FromRequest, FromRequestParts};
use axum::extract::{FromRequest, FromRequestParts, Request};
use axum::response::IntoResponse;
use http::request::Parts;
use http::Request;
use std::fmt::Debug;
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
@@ -118,7 +116,7 @@ where
{
type Rejection = R;
async fn from_request(req: Request<Body>, state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
let extractor = E::from_request(req, state).await?;
Ok(WithRejection(extractor, PhantomData))
}
@@ -141,6 +139,7 @@ where
#[cfg(test)]
mod tests {
use axum::body::Body;
use axum::extract::FromRequestParts;
use axum::http::Request;
use axum::response::Response;
+2 -1
View File
@@ -1,6 +1,7 @@
//! Additional handler utilities.
use axum::body::Body;
use axum::extract::Request;
use axum::{
extract::FromRequest,
handler::Handler,
@@ -174,7 +175,7 @@ where
{
type Future = BoxFuture<'static, Response>;
fn call(self, req: http::Request<Body>, state: S) -> Self::Future {
fn call(self, req: Request, state: S) -> Self::Future {
let req = req.map(Body::new);
Box::pin(async move {
match T::from_request(req, &state).await {
+2 -4
View File
@@ -1,10 +1,8 @@
use super::HandlerCallWithExtractors;
use crate::either::Either;
use axum::{
body::Body,
extract::{FromRequest, FromRequestParts},
extract::{FromRequest, FromRequestParts, Request},
handler::Handler,
http::Request,
response::{IntoResponse, Response},
};
use futures_util::future::{BoxFuture, Either as EitherFuture, FutureExt, Map};
@@ -67,7 +65,7 @@ where
// this puts `futures_util` in our public API but thats fine in axum-extra
type Future = BoxFuture<'static, Response>;
fn call(self, req: Request<Body>, state: S) -> Self::Future {
fn call(self, req: Request, state: S) -> Self::Future {
Box::pin(async move {
let (mut parts, body) = req.into_parts();
+2 -3
View File
@@ -3,13 +3,12 @@
use axum::{
async_trait,
body::Body,
extract::FromRequest,
extract::{FromRequest, Request},
response::{IntoResponse, Response},
BoxError,
};
use bytes::{BufMut, BytesMut};
use futures_util::stream::{BoxStream, Stream, TryStream, TryStreamExt};
use http::Request;
use pin_project_lite::pin_project;
use serde::{de::DeserializeOwned, Serialize};
use std::{
@@ -108,7 +107,7 @@ where
{
type Rejection = Infallible;
async fn from_request(req: Request<Body>, _state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection> {
// `Stream::lines` isn't a thing so we have to convert it into an `AsyncRead`
// so we can call `AsyncRead::lines` and then convert it back to a `Stream`
let body = req.into_body();
+12 -13
View File
@@ -2,12 +2,11 @@
use axum::{
async_trait,
body::Body,
extract::{rejection::BytesRejection, FromRequest},
extract::{rejection::BytesRejection, FromRequest, Request},
response::{IntoResponse, Response},
};
use bytes::{Bytes, BytesMut};
use http::{Request, StatusCode};
use http::StatusCode;
use prost::Message;
use std::ops::{Deref, DerefMut};
@@ -104,7 +103,7 @@ where
{
type Rejection = ProtobufRejection;
async fn from_request(req: Request<Body>, state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
let mut bytes = Bytes::from_request(req, state).await?;
match T::decode(&mut bytes) {
@@ -286,16 +285,16 @@ mod tests {
result: String,
}
let app = Router::new().route(
"/",
post(|input: Protobuf<Input>| async move {
let output = Output {
result: input.foo.to_owned(),
};
#[axum::debug_handler]
async fn handler(input: Protobuf<Input>) -> Protobuf<Output> {
let output = Output {
result: input.foo.to_owned(),
};
Protobuf(output)
}),
);
Protobuf(output)
}
let app = Router::new().route("/", post(handler));
let input = Input {
foo: "bar".to_owned(),
+3 -4
View File
@@ -1,8 +1,7 @@
//! Additional types for defining routes.
use axum::{
body::Body,
http::Request,
extract::Request,
response::{IntoResponse, Redirect, Response},
routing::{any, MethodRouter},
Router,
@@ -166,7 +165,7 @@ pub trait RouterExt<S>: sealed::Sealed {
/// This works like [`RouterExt::route_with_tsr`] but accepts any [`Service`].
fn route_service_with_tsr<T>(self, path: &str, service: T) -> Self
where
T: Service<Request<Body>, Error = Infallible> + Clone + Send + 'static,
T: Service<Request, Error = Infallible> + Clone + Send + 'static,
T::Response: IntoResponse,
T::Future: Send + 'static,
Self: Sized;
@@ -269,7 +268,7 @@ where
#[track_caller]
fn route_service_with_tsr<T>(mut self, path: &str, service: T) -> Self
where
T: Service<Request<Body>, Error = Infallible> + Clone + Send + 'static,
T: Service<Request, Error = Infallible> + Clone + Send + 'static,
T::Response: IntoResponse,
T::Future: Send + 'static,
Self: Sized,