1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
use crate::codec::{Encode, Encoder}; use crate::generic::server::{streaming, StreamingService}; use futures::{try_ready, Future, Poll, Stream}; use std::fmt; pub struct ResponseFuture<T, S> where T: StreamingService<S>, S: Stream<Error = crate::Status>, S::Item: prost::Message + Default, T::Response: prost::Message, { inner: Inner<T::Future, T::Response>, } type Inner<T, U> = streaming::ResponseFuture<T, Encoder<U>>; impl<T, S> ResponseFuture<T, S> where T: StreamingService<S>, S: Stream<Error = crate::Status>, S::Item: prost::Message + Default, T::Response: prost::Message, { pub(crate) fn new(inner: Inner<T::Future, T::Response>) -> Self { ResponseFuture { inner } } } impl<T, S> Future for ResponseFuture<T, S> where T: StreamingService<S>, S: Stream<Error = crate::Status>, S::Item: prost::Message + Default, T::Response: prost::Message, { type Item = http::Response<Encode<T::ResponseStream>>; type Error = crate::error::Never; fn poll(&mut self) -> Poll<Self::Item, Self::Error> { let response = try_ready!(self.inner.poll()); let response = response.map(Encode::new); Ok(response.into()) } } impl<T, S> fmt::Debug for ResponseFuture<T, S> where T: StreamingService<S> + fmt::Debug, S: Stream<Error = crate::Status> + fmt::Debug, S::Item: prost::Message + Default + fmt::Debug, T::Response: prost::Message + fmt::Debug, T::ResponseStream: fmt::Debug, T::Future: fmt::Debug, { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("streaming::ResponseFuture") .field("inner", &self.inner) .finish() } }