Rust examples of “parse, don’t validate”
Representing a validated invariant in a type can remove repeated checks and unreachable branches from Rust callers. Eli Bendersky walks through non-empty collections and path types, showing how construction can establish guarantees that ordinary Vec and path APIs do not carry.
The Lobsters discussion surfaced two useful caveats: refining paths to UTF-8 is unsuitable for filesystems that permit arbitrary path bytes, and a NonEmpty representation that stores its head separately may require a copy and complicate slice access. The author defended the representation as making emptiness unrepresentable, while noting that real-world performance comparisons would be useful.