tower_grpc/client/
unary.rs

1use super::client_streaming;
2use crate::error::Error;
3use crate::Body;
4
5use futures::{stream, Future, Poll};
6use http::Response;
7use prost::Message;
8use std::fmt;
9
10pub struct ResponseFuture<T, U, B: Body> {
11    inner: client_streaming::ResponseFuture<T, U, B>,
12}
13
14pub type Once<T> = stream::Once<T, crate::Status>;
15
16impl<T, U, B: Body> ResponseFuture<T, U, B> {
17    /// Create a new client-streaming response future.
18    pub(crate) fn new(inner: client_streaming::ResponseFuture<T, U, B>) -> Self {
19        ResponseFuture { inner }
20    }
21}
22
23impl<T, U, B> Future for ResponseFuture<T, U, B>
24where
25    T: Message + Default,
26    U: Future<Item = Response<B>>,
27    U::Error: Into<Error>,
28    B: Body,
29    B::Error: Into<Error>,
30{
31    type Item = crate::Response<T>;
32    type Error = crate::Status;
33
34    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
35        self.inner.poll()
36    }
37}
38
39impl<T, U, B> fmt::Debug for ResponseFuture<T, U, B>
40where
41    T: fmt::Debug,
42    U: fmt::Debug,
43    B: Body + fmt::Debug,
44    B::Data: fmt::Debug,
45{
46    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47        f.debug_struct("ResponseFuture")
48            .field("inner", &self.inner)
49            .finish()
50    }
51}