What people say. Recommended as a helpful guide for learning clean and idiomatic error handling patterns in Rust.
m
u/meowsqueakin r/rust • Recommends
On “What are some Rust practices you learned in a real workplace? ”
I've spent a few months writing real Rust production code, so I can perhaps share my experience.
----
I have found Rust's type system very effective at constraining data to valid values, and simplifying the downstream code. A lot of my work involves parsing and data conversion, and I find the `struct` + `enum` building blocks to be very powerful for modelling the input and output data. Then conversion often becomes a large set of `TryFrom` or `From` trait implementations. For anything that can only be validated at run-time, I use private struct members and constructors. This significantly reduces the test space, as well as allowing me to leverage validity assumptions further down the data…