serde-rs / bytes

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

Implement Deserialize/Serialize for Option #20

Closed djc closed 4 years ago

djc commented 4 years ago

It'd be nice if I could handle Option<&'a [u8]> directly through #[serde(with = "serde_bytes")].

djc commented 4 years ago

I've simplified the impls to just wrap Option<T> around T: Deserialize/T: Serialize, and added a basic test for Some and None. Since this otherwise relies on the existing impls, it didn't seem like any more exhausting testing was needed, but let me know if you feel otherwise.

djc commented 4 years ago

@dtolnay friendly reminder?

djc commented 4 years ago

Ah, you're right -- it's more subtle than I expected. I think this version solves the issues.

dtolnay commented 4 years ago

I merged an alternative implementation in #21 and published 0.11.4 with the impls. Thanks!

djc commented 4 years ago

Thanks for finishing this up, and sorry for being a bit iterative and not doing more upfront testing.