refactor(body): use HttpBody with extra bounds instead of Payload trait
This commit is contained in:
		
				
					committed by
					
						 Sean McArthur
						Sean McArthur
					
				
			
			
				
	
			
			
			
						parent
						
							203621e3be
						
					
				
				
					commit
					aac0e2dd57
				
			| @@ -1,13 +1,13 @@ | ||||
| use std::error::Error as StdError; | ||||
|  | ||||
| use crate::body::Payload; | ||||
| use crate::body::HttpBody; | ||||
| use crate::common::{task, Future, Poll}; | ||||
| use crate::{Request, Response}; | ||||
|  | ||||
| /// An asynchronous function from `Request` to `Response`. | ||||
| pub trait HttpService<ReqBody>: sealed::Sealed<ReqBody> { | ||||
|     /// The `Payload` body of the `http::Response`. | ||||
|     type ResBody: Payload; | ||||
|     /// The `HttpBody` body of the `http::Response`. | ||||
|     type ResBody: HttpBody; | ||||
|  | ||||
|     /// The error type that can occur within this `Service`. | ||||
|     /// | ||||
| @@ -29,7 +29,7 @@ pub trait HttpService<ReqBody>: sealed::Sealed<ReqBody> { | ||||
| impl<T, B1, B2> HttpService<B1> for T | ||||
| where | ||||
|     T: tower_service::Service<Request<B1>, Response = Response<B2>>, | ||||
|     B2: Payload, | ||||
|     B2: HttpBody, | ||||
|     T::Error: Into<Box<dyn StdError + Send + Sync>>, | ||||
| { | ||||
|     type ResBody = B2; | ||||
| @@ -49,7 +49,7 @@ where | ||||
| impl<T, B1, B2> sealed::Sealed<B1> for T | ||||
| where | ||||
|     T: tower_service::Service<Request<B1>, Response = Response<B2>>, | ||||
|     B2: Payload, | ||||
|     B2: HttpBody, | ||||
| { | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -4,7 +4,7 @@ use std::fmt; | ||||
| use tokio::io::{AsyncRead, AsyncWrite}; | ||||
|  | ||||
| use super::{HttpService, Service}; | ||||
| use crate::body::Payload; | ||||
| use crate::body::HttpBody; | ||||
| use crate::common::{task, Future, Poll}; | ||||
|  | ||||
| // The same "trait alias" as tower::MakeConnection, but inlined to reduce | ||||
| @@ -41,7 +41,7 @@ where | ||||
| // Just a sort-of "trait alias" of `MakeService`, not to be implemented | ||||
| // by anyone, only used as bounds. | ||||
| pub trait MakeServiceRef<Target, ReqBody>: self::sealed::Sealed<(Target, ReqBody)> { | ||||
|     type ResBody: Payload; | ||||
|     type ResBody: HttpBody; | ||||
|     type Error: Into<Box<dyn StdError + Send + Sync>>; | ||||
|     type Service: HttpService<ReqBody, ResBody = Self::ResBody, Error = Self::Error>; | ||||
|     type MakeError: Into<Box<dyn StdError + Send + Sync>>; | ||||
| @@ -70,8 +70,8 @@ where | ||||
|     ME: Into<Box<dyn StdError + Send + Sync>>, | ||||
|     S: HttpService<IB, ResBody = OB, Error = E>, | ||||
|     F: Future<Output = Result<S, ME>>, | ||||
|     IB: Payload, | ||||
|     OB: Payload, | ||||
|     IB: HttpBody, | ||||
|     OB: HttpBody, | ||||
| { | ||||
|     type Error = E; | ||||
|     type Service = S; | ||||
| @@ -94,8 +94,8 @@ impl<T, Target, S, B1, B2> self::sealed::Sealed<(Target, B1)> for T | ||||
| where | ||||
|     T: for<'a> Service<&'a Target, Response = S>, | ||||
|     S: HttpService<B1, ResBody = B2>, | ||||
|     B1: Payload, | ||||
|     B2: Payload, | ||||
|     B1: HttpBody, | ||||
|     B2: HttpBody, | ||||
| { | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ use std::error::Error as StdError; | ||||
| use std::fmt; | ||||
| use std::marker::PhantomData; | ||||
|  | ||||
| use crate::body::Payload; | ||||
| use crate::body::HttpBody; | ||||
| use crate::common::{task, Future, Poll}; | ||||
| use crate::{Request, Response}; | ||||
|  | ||||
| @@ -45,10 +45,10 @@ impl<F, ReqBody, Ret, ResBody, E> tower_service::Service<crate::Request<ReqBody> | ||||
|     for ServiceFn<F, ReqBody> | ||||
| where | ||||
|     F: FnMut(Request<ReqBody>) -> Ret, | ||||
|     ReqBody: Payload, | ||||
|     ReqBody: HttpBody, | ||||
|     Ret: Future<Output = Result<Response<ResBody>, E>>, | ||||
|     E: Into<Box<dyn StdError + Send + Sync>>, | ||||
|     ResBody: Payload, | ||||
|     ResBody: HttpBody, | ||||
| { | ||||
|     type Response = crate::Response<ResBody>; | ||||
|     type Error = E; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user