Closed sgued closed 10 months ago
I'd love to see this added, would it be possible for a maintainer to have a look at it?
I am also really interested in this. Any chance you could have a look @dtolnay ?
Note that unlike serde
serde_bytes
doesn't have the impl Serialize for [T; 0]
problem
This is blocking downstream feature in Avro/Rust for Fixed Types. I've tested it, and it works fine for my use case with Avro.
Can this be merged soon please ?
Haha, I created a pull request with almost exactly the same name, not realizing that this existed (I'll delete it now). But, can we please get this merged in?
Given the lack of activity in this PR we published a similar crate specifically for [u8; N]
as serde-byte-array
The serde_with::Bytes
type supports const generic arrays in a bunch of ways.
Does anyone know why this is taking so long? I.e., should I wait for a fix or should I switch to a different crate?
in case anyone looking for drop-in replacement with all bytes/slice support in one crate, can use this https://github.com/so-schen/serde-bytes-ng
Hi.
This PR adds support for constant length byte arrays
[u8; N]
and adds aByteArray<const N: usize>
wrapper type similar toBytesBuf
. This would close #26.Motivations
Fixed sized array are often used for cryptography and embedded systems. Having efficient support to serialize/deserialize keys would be great.
Parts of the PR requiring discussion
I'm not sure why
ByteBuf
andBytes
implementsPartialEq
andPartialOrd
for types implementingAsRef<[u8]>
and notBorrow<[u8]>
. ByteArray implementsPartialEq
/Ord
with types implementingBorrow<[u8; N]>
so that it can be compared to itself and to[u8; N]
It might be worth considering adding a
new_mut(&mut [u8]) -> Bytes
function toBytes
so that the same (unsafe) code is reused for theBorrowMut<Bytes>
implementations ofByteArray
andByteBuf
.Drawbacks
Due to the use of const generics, this would require raising the MSRV to 1.53 (which could be lowered to 1.51 by removing the
IntoIterator
implementation).Edit: Since 0504fcb86133c78a75560c907556f1d6031bdf23 already bumped MSRV to 1.56, this drawback doesn't apply anymore.