3 ms·
There's not much to it. It works really nice and is super easy if you can deserialize to Rust's records. In most cases the code can just be generated but there'
by GreaterFool 9y ago
There's not much to it. It works really nice and is super easy if you can deserialize to Rust's records. In most cases the code can just be generated but there's also an option to override `serializer` and `deserializer` for specific fields. So you can generate most and have one custom for instance. That's great.
However, I was parsing some ugly format that doesn't deserialize cleanly:
match v.as_slice() {
&[Value::String(ref s), Value::Object(ref o)]
if s.as_str() == "i" => {
// more code here and still need to unpack x and y from o
}
to parse something like `["i", {"x": ..., "y": ...}]`. In Haskell you could do:
case j of
Array [String "i", Object o] | Just x <- HashMap.lookup "x" o, Just y <- HashMap.lookup "y" o ->
// code goes here, can refer to x and y
- steveklabnik 9y agoInteresting, thanks!