use bytes::IntoBuf; use futures::{Poll}; use http; use hyper::body::Payload; use tower_grpc as grpc; #[derive(Debug)] pub struct GrpcBody(B); // ===== impl GrpcBody ===== impl GrpcBody { pub fn new(inner: B) -> Self { GrpcBody(inner) } } impl Payload for GrpcBody where B: grpc::Body + Send + 'static, B::Data: Send + 'static, ::Buf: Send + 'static, { type Data = ::Buf; type Error = h2::Error; fn is_end_stream(&self) -> bool { grpc::Body::is_end_stream(&self.0) } fn poll_data(&mut self) -> Poll, Self::Error> { let data = try_ready!(grpc::Body::poll_data(&mut self.0)); Ok(data.map(IntoBuf::into_buf).into()) } fn poll_trailers(&mut self) -> Poll, Self::Error> { grpc::Body::poll_metadata(&mut self.0).map_err(From::from) } } impl grpc::Body for GrpcBody where B: grpc::Body, { type Data = B::Data; fn is_end_stream(&self) -> bool { grpc::Body::is_end_stream(&self.0) } fn poll_data(&mut self) -> Poll, grpc::Error> { grpc::Body::poll_data(&mut self.0) } fn poll_metadata(&mut self) -> Poll, grpc::Error> { grpc::Body::poll_metadata(&mut self.0) } }