3 ms·
This sounds really useful, you don't happen to have an example of this do you? Thanks in advance!
by EwanToo 8y ago
This sounds really useful, you don't happen to have an example of this do you?
Thanks in advance!
- rusbus 8y agoHi -- OP here. I actually do it in the tests (but for TOML): https://github.com/rcoh/angle-grinder/blob/master/tests/integration.rs#L10-L16 https://github.com/rcoh/angle-grinder/blob/master/tests/inte... https://github.com/rcoh/angle-grinder/blob/master/tests/structured_tests/count_distinct.toml https://github.com/rcoh/angle-grinder/blob/master/tests/stru...
- deleted 8y ago[deleted]
- _hardwaregeek 8y agoI’m basically talking about Serde. Read the section titled “Parsing JSON as strongly typed data structures”. What’s nice is that you don’t have to include all the fields in the JSON in the struct. Serde will only give you the ones defined by the struct. https://github.com/serde-rs/json/blob/master/README.md https://github.com/serde-rs/json/blob/master/README.md
- hu3 8y agoI'm not sure I'd consider that lib any safer than the average serialization library when things like this happen: https://github.com/serde-rs/json/issues/464 https://github.com/serde-rs/json/issues/464
- steveklabnik 8y agoPanics are memory safe, so that’s still more safe than many parsing bugs.
- hu3 8y agoThe issue does not mention memory safety and neither did I. Honestly, knee-jerk reactions like "BUT MUH MEMORY SAFETY" doesn't inspire confidence specially when it couldn't help saving that dev from the troubles and bugs documented in the issue. To quote a few: > it was a hassle to track down because Rust itself didn't complain and the panic message during serialization wouldn't tell me which file of the hundreds of thousands was causing it to die. For lack of a purpose-built tool, I had to manually bisect it until I narrowed it down. > That said, definitely a footgun in the standard library to be remedied. > My main concern here is getting rid of the footgun if at all possible. I really don't want to have to maintain a special "Never allow these types to creep into structs I'm deriving Serialize/Deserialize on, because the compiler certainly won't warn you" audit list. If that's considered safe in Rust's standards then I rest my case.
- steveklabnik 8y agoMemory safety issues plague parsers, and often have dire consequences. rust claims to be memory safe. This bug does not invoke memory unsafety. Yes, things can still be improved, but this is nowhere near as bad as many parsing bugs.
- oconnor663 8y agoSafe in rust usually has a very specific meaning: https://doc.rust-lang.org/nomicon/what-unsafe-does.html https://doc.rust-lang.org/nomicon/what-unsafe-does.html
- zanny 8y agohttps://gitlab.com/zanny/oidc-reqwest/blob/master/src/token.rs#L11 https://gitlab.com/zanny/oidc-reqwest/blob/master/src/token.... You can declare structs that derive from Serde and convert to / from Json in a typesafe way.