Trending storyWatching
Rusty thoughts on 'Parse, don't validate'
1 report1 sourceupdated 2 days ago
What happened
Summary
Eli Bendersky 用 Rust 重新解读 Alexis King 那篇经典文章「Parse, don't validate」。核心思路很简单:别在运行时反复检查数据是否合法,而是用类型把约束写死。比如用 NonEmpty 类型代替 Vec,保证列表不可能为空,这样调用 first() 时就不用再处理 Option。文章举了 POSIX 工具和...
Coverage
Follow the reports to see the story from different sides.
Sep 27
- Hacker News front pageRusty thoughts on 'Parse, don't validate'
Eli Bendersky revisits the 'Parse, don't validate' pattern in Rust. The key idea: use types like NonEmpty to enforce invariants at compile time, so you never need to re-check emptiness at runtime. Examples from POSIX utilities and rust-analyzer's AbsPathBuf show how to turn validation into parsing. The post doesn't discuss performance numbers or community debates.
Heat over time
Not enough continuous observations to draw a trend yet.