Skip to content

Commit

Permalink
Implement Default for HttpBody1ToHttpBody04 (#4)
Browse files Browse the repository at this point in the history
see hyperium/tonic#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<Option<Result<Frame<Self::Data>, 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::<Bytes>::new()).poll_frame(cx).map_err(|_| unreachable!())
        }
    }
}
```
  • Loading branch information
howardjohn authored Mar 13, 2023
1 parent 3a4e578 commit db9e00b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B> {
#[pin]
body: B,
Expand Down

0 comments on commit db9e00b

Please sign in to comment.