From db9e00bfc696c1de9579f9f01a8d0a2ee0f955c9 Mon Sep 17 00:00:00 2001 From: John Howard Date: Mon, 13 Mar 2023 08:51:17 -0700 Subject: [PATCH] Implement `Default` for `HttpBody1ToHttpBody04` (#4) see https://github.com/hyperium/tonic/issues/1307 Tonic interceptors require a Default on the body. This makes it easier to use an adapter type tonic. FWIW the default type I am using: ```rust #[derive(Default)] pub enum DefaultIncoming { Some(Incoming), #[default] Empty } impl Body for DefaultIncoming { type Data = Bytes; type Error = hyper::Error; fn poll_frame(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll, Self::Error>>> { match self.get_mut() { DefaultIncoming::Some(ref mut i) => Pin::new(i).poll_frame(cx), DefaultIncoming::Empty => Pin::new(&mut http_body_util::Empty::::new()).poll_frame(cx).map_err(|_| unreachable!()) } } } ``` --- src/body.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/body.rs b/src/body.rs index 66fb3c6..a1879fd 100644 --- a/src/body.rs +++ b/src/body.rs @@ -78,7 +78,7 @@ pin_project! { /// /// [http-body 0.4 `Body`]: https://docs.rs/http-body/latest/http_body/trait.Body.html /// [http-body 1.0 `Body`]: https://docs.rs/http-body/1.0.0-rc.2/http_body/trait.Body.html - #[derive(Debug, Clone)] + #[derive(Debug, Clone, Default)] pub struct HttpBody1ToHttpBody04 { #[pin] body: B,