Re:Bugs Rust Won't Catch
by JuniperMesos on Wednesday April 29, 2026 @02:06AM
(#47944696)
After reading this article, I'm inclined to think that the right thing for this project to do is write their own library that wraps the Rust stdlib with a file-handle-based API along with one method to get a file handle from a Path; rewrite the code to use that library rather than rust stdlib methods, and then add a lint check that guards against any use of the Rust standard library file methods anywhere outside of that wrapper.
[ Parent
| on HN ]
If that's the right approach, then it would be useful to make that library public as a crate, because writing such hardened code is generally useful. Possibly as a step before inclusion in the rust stdlib itself.
Re:Bugs Rust Won't Catch
by akoboldfrying on Wednesday April 29, 2026 @07:07AM
(#47946678)
Agreed. (This approach feels like a cousin of Parse, Don't Validate.)
Re:Bugs Rust Won't Catch
by JuniperMesos on Wednesday April 29, 2026 @03:00PM
(#47952795)
Yeah. The idea is, if you're consistently making mistakes because the most convenient API at your disposal (here, the rust standard library file/directory APIs that are based around Paths), then after you fix the actual bugs you should write a better abstraction and then deliberately add friction around not using that better abstraction to try to constrain future developers (including future-you) from using the more-error-prone abstraction.
Parse, don't validate is also a principle that encourages people to use a less-error-prone abstraction (the parsed data structure or an error representing invalid input), rather than a more-error-prone one (the original untyped data with ad-hoc validations at various call sites).