-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Default
for HttpBody1ToHttpBody04
#4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use #[derive(Default)]
?
I don't think so, because we only want to implement |
That is how it works. How else could it create a body? |
Today you can use the adaptor without B: Default though. Derive would mean it MUST be Default, the approach here makes it Default only if the inner type is? In particular, hyper Incoming is not Default so I am not sure we should require it |
I think you're misunderstanding how #[derive(Default)] // this derive...
pub struct HttpBody1ToHttpBody04<B> {
body: B,
trailers: Option<HeaderMap>,
}
// ...is the same as
impl<B: Default> Default for HttpBody1ToHttpBody04<B> {
fn default() -> Self {
Self {
body: B::default(),
trailers: <Option<HeaderMap>>::default(),
}
}
} It does not add this #[derive(Default)]
pub struct HttpBody1ToHttpBody04<B: Default> {
// ^^^^^^^^^^
body: B,
trailers: Option<HeaderMap>,
} |
Oh that is great, thanks for the tip. I wasn't aware the |
Default
for HttpBody1ToHttpBody04
Published in 0.1.3 🎉 |
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: