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 alloc optional (embedded rust) #479

Open
xoac opened this issue Feb 10, 2021 · 11 comments
Open

Make alloc optional (embedded rust) #479

xoac opened this issue Feb 10, 2021 · 11 comments

Comments

@xoac
Copy link

xoac commented Feb 10, 2021

Proposition:
I wonder if is it possible to make alloc optional. As far as I have checked the source code the main problem for make alloc optional is with implementation of Bytes and BytesMut that require alloc to work. To support partially bytes for embedded devices where alloc is not an option theses structs need re-implementation and this is complicated subject. Things that can be introduced to embedded word are Buf and BufMut traits and this works nearly out of the box.

Motivation:

  • common interface for bytes on every level of rust

Here is example where alloc crate is a problem:


Crate that could benefits from proposed changes:

@taiki-e
Copy link
Member

taiki-e commented Feb 10, 2021

As said in #461 (comment), I don't think it's possible without breaking changes. See also crossbeam-rs/crossbeam#508 (comment).

@xoac
Copy link
Author

xoac commented Feb 11, 2021

So now the question is a little bit political. Are authors interested to make bytes crate embedded devices friendly? Since this issue was know before first major release maybe "not make alloc optional" was considered decision?

I think breaking changes are not a problem here, since you can just simply increment major release.

@taiki-e
Copy link
Member

taiki-e commented Feb 12, 2021

The main problem is that we recently released v1 and don't want to release v2 right away.

Since this issue was know before first major release maybe "not make alloc optional" was considered decision?

I don't think there was such a decision. I knew about such an issue, but I wasn't noticed that bytes had a similar issue until #461 reported.

To be clear: I'm basically in favor of doing this in the next major version.

@Kixunil
Copy link

Kixunil commented Jan 12, 2022

There is a way to achieve embedded compatibility (and I hope MSRV 1.36) without breaking bytes API: jut move the traits only to a separate bytes-traits crate and reexport/implement them here. The embedded consumers can simply depend on that crate instead of bytes. I'm willing to make a PR for this.

@taiki-e
Copy link
Member

taiki-e commented Jan 12, 2022

There is a way to achieve embedded compatibility (and I hope MSRV 1.36) without breaking bytes API: jut move the traits only to a separate bytes-traits crate and reexport/implement them here. The embedded consumers can simply depend on that crate instead of bytes. I'm willing to make a PR for this.

Note that in this approach, it will break if the user runs cargo update after implementing the traits provided by the old version of bytes crate and the traits provided by bytes-traits crate.

@Kixunil
Copy link

Kixunil commented Jan 12, 2022

@taiki-e isn't it the same problem as having two different versions of a crate?

@taiki-e
Copy link
Member

taiki-e commented Jan 12, 2022

@Kixunil "the old version of bytes crate" meant the 1.x.y version that does not contain the changes you suggested.

They are different traits in the 1.x.y version that does not contain the changes you suggested, but they are the same trait in the version that contains the changes.

@Kixunil
Copy link

Kixunil commented Jan 12, 2022

I don't think it's a problem though. Either you have two version of the bytes crate but the same problem would happen without reexport or you have a single version and then it's non-issue.

I think you're describing this situation, please LMK if you mean something else
assuming bytes_old -> bytes_new is a minor or patch release, bytes_new moves the trait to a separate crate

  • A depends on bytes_old

  • B depends on bytes_old

  • C depends on A and B, supplying A with types from B

  • B changes to implement the traits from bytes-traits and stops depending on bytes

  • C updates the version of B without updating bytes_old

C no longer compiles

In this case B is the one doing breaking change, not bytes.
B can also trivially improve it using the semver trick:

  • B_non_breaking depends on B_breaking AND bytes_new
  • B_breaking implements the change

@nils-van-zuijlen
Copy link

Wouldn't it be possible to have alloc as a default feature flag the way that serde does it?

As I see it, the only people that would be affected by that change would be the no_std group which have set the default-features = false, and not the wider audience that uses std via the default features.

@taiki-e
Copy link
Member

taiki-e commented Jan 2, 2024

@nils-van-zuijlen Please read previous comments (#479 (comment) and #479 (comment)).

@Kixunil
Copy link

Kixunil commented Jan 3, 2024

@taiki-e I think I addressed that in my comment. Is there a specific scenario I'm missing?

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

No branches or pull requests

4 participants