serde-rs / bytes

Wrapper types to enable optimized handling of &[u8] and Vec<u8>
Apache License 2.0
317 stars 37 forks source link

WIP: Add support for heapless::Vec #18

Closed nickray closed 4 years ago

nickray commented 4 years ago

For embedded use cases, instead of alloc it's often preferable to use heapless: fixed-capacity strings and vectors. This patch would allow serializing Vec<u8> as byte strings instead of generic vectors.

A minimal example: https://github.com/nickray/serde-bytes-heapless-test/blob/master/src/lib.rs

I think it would be nice to have this patch here, would that make sense? The alternative being heapless having a Bytes type itself (https://github.com/japaric/heapless/issues/138).

Regarding tests, I'm not sure how they could be added.

Regarding error handling, I'm not sure if or how to map capacity errors when deserializing instead of horribly panicking.

nickray commented 4 years ago

Understood. I am currently maintaining https://crates.io/crates/heapless-bytes and working towards merging this into heapless proper (https://github.com/japaric/heapless/pull/164).