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

Removing Bytes from the public API #366

Closed
seanmonstar opened this issue Nov 28, 2019 · 4 comments · Fixed by #369
Closed

Removing Bytes from the public API #366

seanmonstar opened this issue Nov 28, 2019 · 4 comments · Fixed by #369
Labels
B-rfc Blocked: request for comments. More discussion would help move this along.
Milestone

Comments

@seanmonstar
Copy link
Member

We'd like to disconnect the stability if the http crate from the bytes crate. However, using Bytes inside https types facilitates improved performance by reducing copies (especially as headers and URIs can be quite long in the real world).

This proposes a way forward without sacrificing either case:

  • Remove all public APIs that uses Bytes. This includes from_shared, TryFrom impls, and into_bytes methods.
  • Add from_maybe_shared<T: AsRef<[u8]> + 'static> constructors to types that would most benefit. These constructors could downcast the value into a Bytes if the versions match, and perform a copy if they don't. While a copy not caught at compile-time is unfortunate, the alternatives seem worse.
@seanmonstar seanmonstar added this to the 0.2 milestone Nov 28, 2019
@seanmonstar seanmonstar added the B-rfc Blocked: request for comments. More discussion would help move this along. label Nov 28, 2019
@seanmonstar
Copy link
Member Author

As always, the tricky part is naming:

  • from_maybe_shared
  • from_shared_maybe_copy
  • from_maybe_copy
  • ?

@davidbarsky
Copy link
Contributor

With from_bytes reserved for from_bytes(&[u8]) (with an implicit '_ lifetime), from_maybe_shared<T: AsRef<[u8]> + 'static> feels like the correct name until Bytes is 1.0, at which point, this could be revisited.

@DoumanAsh
Copy link

Could we return it to API now that there is stable version of bytes?

@tesaguri
Copy link
Contributor

tesaguri commented Sep 1, 2021

Could we return it to API now that there is stable version of bytes?

PR #470 aims to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-rfc Blocked: request for comments. More discussion would help move this along.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants