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

Use iovec instead of std::io in no_std builds? #282

Closed
cbeck88 opened this issue Aug 13, 2019 · 4 comments
Closed

Use iovec instead of std::io in no_std builds? #282

cbeck88 opened this issue Aug 13, 2019 · 4 comments

Comments

@cbeck88
Copy link
Contributor

cbeck88 commented Aug 13, 2019

Until #263 was merged in June, tokio-rs/bytes could have built cleanly as a no_std library, grabbing Vec etc. from the alloc crate.

After the move to std::io::IoSlice, it becomes impossible for the crate to expose the same interface in std mode and in alloc mode, so either we can no longer support no_std development or we must embrace features that are not additive... both of which are pretty painful in projects that do no_std development

Can we bring back the iovec dependency as an optional dependency and use it instead of IoSlice, when available? That will make it easier to use bytes in projects that build some targets as no_std and some targets as std. I can describe my usecase in more detail if that is helpful, but these kinds of interface changes across no_std and std are the source of a lot of pain especially for example in serde

@carllerche
Copy link
Member

Why would it not be sufficient to feature gate those fns on a std feature?

@cbeck88
Copy link
Contributor Author

cbeck88 commented Aug 13, 2019

There might be libs that use bytes that use those functions, that would be portable to no_std environment, if iovec were still used

If I had such a lib that I needed to use in no_std environment, I would be tempted to essentially revert #263 and use bytes that way, to get my dependency to work.

I guess it would also work to just pin bytes at 0.4, but if they've already switched to IoSlice then it won't work

@cbeck88
Copy link
Contributor Author

cbeck88 commented Aug 13, 2019

Maybe you are right, there might not be a real use-case for this, if the user of bytes has already switched to std::io::IoSlice then there won't be any easy way to port them. It just seems to me that if IoVec is portable and IoSlice isn't then #263 was a loss

@cbeck88
Copy link
Contributor Author

cbeck88 commented Aug 13, 2019

I think we should close this, sorry for noise

It's really too bad they didn't put IoSlice in core or alloc or something if it would have worked there.

I think that since you already have some partial dependency on std::io for the Reader etc. functions, there is no way to avoid having an std feature and using feature gating if you want to build in no_std environment. So it's not that much worse to just use IoSlice and feature gating for that as well, and it's a lot more complicated to have both IoSlice and IoVec in the mix

@cbeck88 cbeck88 closed this as completed Aug 13, 2019
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

2 participants