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
use crate::codec::{Encode, Encoder}; use crate::generic::server::{client_streaming, unary, ClientStreamingService}; use futures::{try_ready, Future, Poll, Stream}; use std::fmt; pub struct ResponseFuture<T, S> where T: ClientStreamingService<S>, S: Stream<Error = crate::Status>, { inner: Inner<T::Future, T::Response>, } type Inner<T, U> = client_streaming::ResponseFuture<T, Encoder<U>>; impl<T, S> ResponseFuture<T, S> where T: ClientStreamingService<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: ClientStreamingService<S>, S: Stream<Error = crate::Status>, S::Item: prost::Message + Default, T::Response: prost::Message, { type Item = http::Response<Encode<unary::Once<T::Response>>>; 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: ClientStreamingService<S> + fmt::Debug, S: Stream<Error = crate::Status> + fmt::Debug, T::Response: fmt::Debug, T::Future: fmt::Debug, { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("client_streaming::ResponseFuture") .field("inner", &self.inner) .finish() } }