-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
make AnyBody
generic on Body
type
#2448
Conversation
3403095
to
0b13d27
Compare
AnyBody
generic on Body
type
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.
LGTM
@@ -33,39 +36,70 @@ impl AnyBody { | |||
Self::Bytes(Bytes::new()) | |||
} | |||
|
|||
/// Create body from slice (copy) | |||
/// Create boxed body from generic message body. | |||
pub fn new_boxed<B>(body: B) -> Self |
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.
Maybe just call this boxed
?
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.
toyed wth the idea yea
the counter argument is that boxed
is well known as a combinator-style method in futures-util: https://docs.rs/futures-util/0.3.17/futures_util/future/trait.FutureExt.html#method.boxed
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.
Im sure counter examples exist. This shouldn't get used too much i think. I just like the idea of being explicit about its function and that new
and new_boxed
would be together in the docs.rs sidebar.
PR Type
Refactor
PR Checklist
Overview
Big clean up. Altering
AnyBody
to be generic on the "other" body type and finally removingResponseBody
.One more egonomic improvement after this will be a method on HttpResponseBuilder for matching the B parameter and another method for boxing the body. These should greatly reduce the number of map_body calls needed currently when handling polymorphic response bodies.