mod grpc;
pub(crate) mod client_streaming;
pub(crate) mod server_streaming;
pub(crate) mod streaming;
pub(crate) mod unary;
pub(crate) use self::grpc::Grpc;
use crate::{Request, Response};
use futures::{Future, Stream};
use tower_service::Service;
pub trait StreamingService<RequestStream> {
type Response;
type ResponseStream: Stream<Item = Self::Response, Error = crate::Status>;
type Future: Future<Item = crate::Response<Self::ResponseStream>, Error = crate::Status>;
fn call(&mut self, request: Request<RequestStream>) -> Self::Future;
}
impl<T, S1, S2> StreamingService<S1> for T
where
T: Service<Request<S1>, Response = Response<S2>, Error = crate::Status>,
S1: Stream<Error = crate::Status>,
S2: Stream<Error = crate::Status>,
{
type Response = S2::Item;
type ResponseStream = S2;
type Future = T::Future;
fn call(&mut self, request: Request<S1>) -> Self::Future {
Service::call(self, request)
}
}
pub trait UnaryService<R> {
type Response;
type Future: Future<Item = crate::Response<Self::Response>, Error = crate::Status>;
fn call(&mut self, request: Request<R>) -> Self::Future;
}
impl<T, M1, M2> UnaryService<M1> for T
where
T: Service<Request<M1>, Response = Response<M2>, Error = crate::Status>,
{
type Response = M2;
type Future = T::Future;
fn call(&mut self, request: Request<M1>) -> Self::Future {
Service::call(self, request)
}
}
pub trait ClientStreamingService<RequestStream> {
type Response;
type Future: Future<Item = crate::Response<Self::Response>, Error = crate::Status>;
fn call(&mut self, request: Request<RequestStream>) -> Self::Future;
}
impl<T, M, S> ClientStreamingService<S> for T
where
T: Service<Request<S>, Response = Response<M>, Error = crate::Status>,
S: Stream<Error = crate::Status>,
{
type Response = M;
type Future = T::Future;
fn call(&mut self, request: Request<S>) -> Self::Future {
Service::call(self, request)
}
}
pub trait ServerStreamingService<R> {
type Response;
type ResponseStream: Stream<Item = Self::Response, Error = crate::Status>;
type Future: Future<Item = crate::Response<Self::ResponseStream>, Error = crate::Status>;
fn call(&mut self, request: Request<R>) -> Self::Future;
}
impl<T, M, S> ServerStreamingService<M> for T
where
T: Service<Request<M>, Response = Response<S>, Error = crate::Status>,
S: Stream<Error = crate::Status>,
{
type Response = S::Item;
type ResponseStream = S;
type Future = T::Future;
fn call(&mut self, request: Request<M>) -> Self::Future {
Service::call(self, request)
}
}