-
-
Notifications
You must be signed in to change notification settings - Fork 274
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
Implement support for conversion to / from heapless::Vec #733
Comments
Apparently there's precedent for the implementation to live in the serialiser's crate. Both postcard and cbor_smol do this. |
I've modified the title of this issue to be more general, as I want to also encompass the option of An |
See also #643 One solution is to mark your field with We'd rather not have crate-specific implementations in bincode if we can help it |
This isn't for encoding / decoding a field containing a vec, but rather to populate a vec with the encoded data (or to take a vec containing a byte stream and decode it into the corresponding data structure). Currently bincode only works with slices or its own Reader and Writer traits, so in order to work with Vecs, (handy when the length of the byte stream is variable), I have to wrap the Vec so that I can implement the Writer trait on it. As a side note: the current format of the Reader trait is such that I would have to do an unnecessary copy of the data, so I end with an asymmetric implementation where I use I have to implement this wrapper in every project I use bincode for, as using a This seems like such a common pairing that it would make sense to have the option to deal with byte streams packaged as Vecs rather than byte slices. I would also argue that this barely qualifies as a crate-specific implementation: |
I am working on a no_std embedded comms stack which talks to devices running C applications. The stack uses
heapless::Vec
s to handle the byte streams being sent and received, and I would like to use bincode to perform the conversion to / from Rust structures.Right now, in order to do this I have to create a wrapper type around the
heapless::Vec
in order to implement bincode'sWriter
andReader
traits. It seems like this is a common enough pairing that it would make sense to have these traits implemented for heapless::Vec by default, or at least available through a feature, rather than having to re-implement for each new project working in this space.I am inclined to think that the implementation should be included within bincode, possibly alongside an implementation for
std::Vec
too, however I have created an equivalent issue on theheapless
repo in case the community thinks that it would make more sense for the implementation to live there.The text was updated successfully, but these errors were encountered: