TIL: serde’s borrowing can be treacherous
(This is not super surprising when you think about it, but it bit me recently so I figured I’d write it up.) TL;DR: Be careful when using &’a str or &’a [u8] with serde deserializers; serde has no way to produce an appropriate compile-time error when zero-copy deserialization isn’t possible or just isn’t supported. Instead, you’ll get a runtime error indefinitely later. serde is Rust’s de facto standard serialization/deserialization framework. It’s also arguably one of the “crown jewels” of the Rust ecosystem, insofar as it’s broadly used and solves a thorny ergonomics problem (corresponding the serialized representation of a structure to its type) without imposting format-specific constraints on the types themselves1. serde also has a degree of support for zero-copy…