Skip to content
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

Merged
merged 7 commits into from
Nov 16, 2021
Merged

make AnyBody generic on Body type #2448

merged 7 commits into from
Nov 16, 2021

Conversation

robjtede
Copy link
Member

@robjtede robjtede commented Nov 16, 2021

PR Type

Refactor

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt.
  • (Team) Label with affected crates and semver status.

Overview

Big clean up. Altering AnyBody to be generic on the "other" body type and finally removing ResponseBody.

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.

@robjtede robjtede added A-http project: actix-http A-web project: actix-web B-semver-major breaking change requiring a major version bump labels Nov 16, 2021
@robjtede robjtede marked this pull request as ready for review November 16, 2021 17:09
@robjtede robjtede requested a review from a team November 16, 2021 17:15
@robjtede robjtede changed the title make AnyBody generic on Stream body type make AnyBody generic on Body type Nov 16, 2021
Copy link
Contributor

@fakeshadow fakeshadow left a 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
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member Author

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.

@robjtede robjtede merged commit d8cbb87 into master Nov 16, 2021
@robjtede robjtede deleted the anybody-generic branch November 16, 2021 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-http project: actix-http A-web project: actix-web B-semver-major breaking change requiring a major version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants