Move service into transport
This commit is contained in:
+32
-7
@@ -9,7 +9,6 @@ pub mod codec;
|
|||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod metadata;
|
pub mod metadata;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
pub mod service;
|
|
||||||
|
|
||||||
#[cfg(feature = "transport")]
|
#[cfg(feature = "transport")]
|
||||||
pub mod transport;
|
pub mod transport;
|
||||||
@@ -21,20 +20,46 @@ mod status;
|
|||||||
pub use body::BoxBody;
|
pub use body::BoxBody;
|
||||||
pub use request::Request;
|
pub use request::Request;
|
||||||
pub use response::Response;
|
pub use response::Response;
|
||||||
pub use service::GrpcService;
|
|
||||||
pub use status::{Code, Status};
|
pub use status::{Code, Status};
|
||||||
pub use tonic_macros::{client, server};
|
pub use tonic_macros::{client, server};
|
||||||
|
|
||||||
pub(crate) use error::Error;
|
pub(crate) use error::Error;
|
||||||
|
|
||||||
|
use crate::body::Body;
|
||||||
|
use http_body::Body as HttpBody;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::sync::Arc;
|
use std::task::{Context, Poll};
|
||||||
|
use tower_service::Service;
|
||||||
|
|
||||||
pub trait GrpcInnerService<Request> {
|
pub trait GrpcService<ReqBody> {
|
||||||
type Response;
|
type ResponseBody: Body + HttpBody;
|
||||||
type Future: Future<Output = Result<Self::Response, Status>>;
|
type Error: Into<crate::Error>;
|
||||||
|
|
||||||
fn call(self: Arc<Self>, request: Request) -> Self::Future;
|
type Future: Future<Output = Result<http::Response<Self::ResponseBody>, Self::Error>>;
|
||||||
|
|
||||||
|
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
|
||||||
|
|
||||||
|
fn call(&mut self, request: http::Request<ReqBody>) -> Self::Future;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, ReqBody, ResBody> GrpcService<ReqBody> for T
|
||||||
|
where
|
||||||
|
T: Service<http::Request<ReqBody>, Response = http::Response<ResBody>>,
|
||||||
|
T::Error: Into<crate::Error>,
|
||||||
|
ResBody: Body + HttpBody,
|
||||||
|
<ResBody as HttpBody>::Error: Into<crate::Error>,
|
||||||
|
{
|
||||||
|
type ResponseBody = ResBody;
|
||||||
|
type Error = T::Error;
|
||||||
|
type Future = T::Future;
|
||||||
|
|
||||||
|
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
|
Service::poll_ready(self, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn call(&mut self, request: http::Request<ReqBody>) -> Self::Future {
|
||||||
|
Service::call(self, request)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
use crate::body::Body;
|
|
||||||
use http::{Request, Response};
|
|
||||||
use http_body::Body as HttpBody;
|
|
||||||
use std::future::Future;
|
|
||||||
use std::task::{Context, Poll};
|
|
||||||
use tower_service::Service;
|
|
||||||
|
|
||||||
pub trait GrpcService<ReqBody> {
|
|
||||||
type ResponseBody: Body + HttpBody;
|
|
||||||
type Error: Into<crate::Error>;
|
|
||||||
|
|
||||||
type Future: Future<Output = Result<Response<Self::ResponseBody>, Self::Error>>;
|
|
||||||
|
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
|
|
||||||
|
|
||||||
fn call(&mut self, request: Request<ReqBody>) -> Self::Future;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, ReqBody, ResBody> GrpcService<ReqBody> for T
|
|
||||||
where
|
|
||||||
T: Service<Request<ReqBody>, Response = Response<ResBody>>,
|
|
||||||
T::Error: Into<crate::Error>,
|
|
||||||
ResBody: Body + HttpBody,
|
|
||||||
<ResBody as HttpBody>::Error: Into<crate::Error>,
|
|
||||||
{
|
|
||||||
type ResponseBody = ResBody;
|
|
||||||
type Error = T::Error;
|
|
||||||
type Future = T::Future;
|
|
||||||
|
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
||||||
Service::poll_ready(self, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, request: Request<ReqBody>) -> Self::Future {
|
|
||||||
Service::call(self, request)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
use tower_make::MakeService;
|
|
||||||
use tower_service::Service;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Reconnect<M> {
|
|
||||||
inner: M,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<M, Target, Request> Service<Target> for Reconnect<M>
|
|
||||||
where
|
|
||||||
M: MakeService<Target, Request>,
|
|
||||||
{
|
|
||||||
type Response = M::Response;
|
|
||||||
type Error = M::Error;
|
|
||||||
type Future = M::Future;
|
|
||||||
|
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
||||||
self.inner.poll_ready(cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, req: Target) -> Self::Future {
|
|
||||||
unimplmented!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
use crate::{
|
use super::service::{AddOrigin, BoxService, ServiceList};
|
||||||
body::BoxBody,
|
use crate::{BoxBody, GrpcService};
|
||||||
service::{AddOrigin, BoxService, GrpcService, ServiceList},
|
|
||||||
};
|
|
||||||
use futures_util::try_future::{MapErr, TryFutureExt};
|
use futures_util::try_future::{MapErr, TryFutureExt};
|
||||||
use http::Uri;
|
use http::Uri;
|
||||||
use hyper::client::conn;
|
use hyper::client::conn;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ mod channel;
|
|||||||
mod openssl;
|
mod openssl;
|
||||||
#[cfg(feature = "rustls")]
|
#[cfg(feature = "rustls")]
|
||||||
mod rustls;
|
mod rustls;
|
||||||
|
mod service;
|
||||||
|
|
||||||
pub use self::channel::Channel;
|
pub use self::channel::Channel;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
mod add_origin;
|
mod add_origin;
|
||||||
mod boxed;
|
mod boxed;
|
||||||
mod grpc;
|
|
||||||
// mod reconnect;
|
|
||||||
mod connect;
|
mod connect;
|
||||||
mod connector;
|
mod connector;
|
||||||
mod discover;
|
mod discover;
|
||||||
@@ -11,4 +9,3 @@ mod tls;
|
|||||||
pub use self::add_origin::AddOrigin;
|
pub use self::add_origin::AddOrigin;
|
||||||
pub use self::boxed::BoxService;
|
pub use self::boxed::BoxService;
|
||||||
pub use self::discover::ServiceList;
|
pub use self::discover::ServiceList;
|
||||||
pub use self::grpc::GrpcService;
|
|
||||||
Reference in New Issue
Block a user