News for hackers. Stuff that matters.
Re:Rusty thoughts on "Parse, don't validate" by tjadfsaj on Sunday September 27, 2026 @10:32AM (#49866965)
Nonempty type wrappers are a stark reminder that we are missing out on refinement types.
Re:Rusty thoughts on "Parse, don't validate" by bunderbunder on Sunday September 27, 2026 @10:47AM (#49867088)
I was thinking about its implementation, too, and ended up deciding that it was probably a performance optimization.

`Vec<T>` stores all data on the heap, so getting anything out of it involves a pointer deref and possibly also an array bounds check. This `NonEmpty<T>` type keeps the first element of the list in a location that supports some low-level optimization that might make a significant difference in situations where accessing the first element is much more common than accessing subsequent elements.

Re:Rusty thoughts on "Parse, don't validate" by andrepd on Sunday September 27, 2026 @10:48AM (#49867102)
Rust has a proposal for this, in the form of pattern types. It's on nightly, but quite far from being ready for prime time.