heapless icon indicating copy to clipboard operation
heapless copied to clipboard

Implement bincode Writer and Reader traits for Vec

Open petekubiak opened this issue 1 year ago • 5 comments

I am working on a no_std embedded comms stack which talks to devices running C applications. The stack uses heapless::Vecs 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's Writer and Reader 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'm not sure whether it would make more sense for this implementation to live in the bincode crate or the heapless crate, so I've created an equivalent issue on the bincode repo. What do you think?

petekubiak avatar Nov 29 '24 14:11 petekubiak

Might be relevant:

  • Postcard provides its own implementations there: https://docs.rs/postcard/latest/postcard/fn.to_vec.html
  • cbor_smol also does the same
  • https://github.com/rust-embedded/heapless/pull/340 might be interesting to get similar functionality without needing dedicated implementations.

sosthene-nitrokey avatar Nov 29 '24 15:11 sosthene-nitrokey

Yeah agreed, to me it would seem like it would make more sense for the implementation to live in the serialiser's crate rather than the collection's crate. Good to know there's precedent.

petekubiak avatar Nov 29 '24 17:11 petekubiak

Hi! Looks like the bincode maintainers have taken the opposite perspective.

Thoughts on how we can resolve?

David-OConnor avatar Jul 01 '25 12:07 David-OConnor

Well if the bin code maintainers are not interested in adding heapless support I guess it's up to the heapless maintainers whether they want to add bincode support...that does seem the wrong way round to me though.

petekubiak avatar Jul 04 '25 18:07 petekubiak

It seems we are at an impasse. I can write a third party integration crate if we have to, but would prefer to resolve this through diplomacy! (C+P from there)

David-OConnor avatar Jul 18 '25 17:07 David-OConnor