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

feat: make alloc optional #606

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GabrielDertoni
Copy link

Currently the no_std support for the crate still depends on alloc. However, this is only required for Bytes and BytesMut data structures and not Buf and BufMut traits or its other impls. This PR makes alloc optional in order to make the crate more suitable for embedded environments.

The main benefit of this change is beeing able to depend only on the Buf and BufMut traits, which is very usefull not only to embedded environments, but also for other crates that would like to use those traits but don't need Bytes and BytesMut. I think this would be a good thing, since it encorages everyone to use bytes and reduce the number of parallel implementations of this same concept.

As an example usecase, rust-mavlink had to pretty much reimplement Buf and BufMut because they don't want a hard dependency on alloc.

This PR adds a alloc default feature that can be disabled if not required. However, maybe it would be better to add a embedded or no_alloc feature instead, so that it doesn't break any code that depends on bytes. Please let me know what you think of this change.

@Darksonn
Copy link
Contributor

Sorry, but this is a breaking change. Code that previously compiled with no features enabled would break. Unfortunately, we also cannot add a no_alloc feature because features must be additive.

@GabrielDertoni
Copy link
Author

Oh, I see. Would it be possible to maybe create a different crate (say we name it bytes-buf) that has only the Buf and BufMut traits implemented for builtin rust types? This new crate would have an alloc feature. Then bytes could depend on bytes-buf with the alloc feature and reexport the traits. Just an idea, don't konw if it's too much of a hassle.

@taiki-e
Copy link
Member

taiki-e commented Mar 20, 2023

See #479 for previous discussions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants