Re:Why static languages suffer from complexity
by adwn on Wednesday January 19, 2022 @02:09PM
(#29998488)
Rust:
let foo: serde_json::Value = serde_json::from_str(arbitraryJsonString)?;
There, just as powerful [1]. But you know what's even more powerful? After you've done your dynamic checks, you can do this on the entire JSON tree, or on a subtree:
let bar: MyStaticType = serde_json::from_value(foo)?;
and you get a fully parsed instance of a static type, with all the guarantees and performance benefits that entails.
[1] Value represents a JSON tree: https://docs.serde.rs/serde_json/enum.Value.html