KokaKiwi / rust-hex

A basic crate to encode values to hexadecimal representation. Originally extracted from rustc-serialize.
https://crates.io/crates/hex
Apache License 2.0
203 stars 57 forks source link

Newtype for serde #65

Open piegamesde opened 3 years ago

piegamesde commented 3 years ago

The serde support of this crate is just plain awesome. I use #[serde(with = "hex::serde")] all the time. However, I just ran into the situation where I want a Vec<Vec<u8>> to be encoded as a list of hex strings. This is a lot less straightforward to implement, sadly.

To make this more ergonomic, I suggest adding a serialization wrapper newtype that I may use instead of serde_with. I could then write something like Vec<HexBytes> or Vec<Hex<Vec<u8>>> and it would just work.

piegamesde commented 3 years ago

Prior art: https://docs.rs/serde_bytes/0.11.5/serde_bytes/ https://github.com/serde-rs/bytes/issues/14 https://github.com/jonasbb/serde_with/pull/277 https://docs.rs/serde_with/1.10.0/serde_with/hex/struct.Hex.html