# Rust 的 Exhaustive Destructuring 为何更安全？

Original title: In Praise of Exhaustive Destructuring

> Hacker News story 48879529 · language: zh · submitted 2026-07-12
> Web version: https://zeli.app/zh/story/48879529
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 50 · by [avandecreme](<https://news.ycombinator.com/user?id=avandecreme>) · 💬 7
[original](<https://antoine.vandecreme.net/blog/exhaustive-destructuring-praise/>) · [HN discussion](<https://news.ycombinator.com/item?id=48879529>)

## Summary

初学 Rust 时，我曾对必须列出所有字段或使用 .. 语法的 Exhaustive Destructuring 感到繁琐，相比之下 TypeScript 和 Haskell 的写法似乎更灵活。但最近我彻底改变了看法：这种看似“啰嗦”的机制其实是维护软件安全的利器。当 WeatherReading 结构体新增 wind_speed 字段时，如果函数参数未显式解构所有字段，编译器不会报错，导致我们可能忽略大风等危险情况。而通过强制解构所有字段，Rust 编译器能直接报错，提醒我们处理新增数据。这不仅适用于函数参数，在实现 From 转换或重构代码时，也能强制开发者明确每个字段的去向，甚至提示哪些字段该独立成新的结构体。

## Key quote

> 如果你看到同一组字段总是被一起解构，而其他字段被忽略，这可能是一个很好的信号，表明这些字段应该被提取到它们自己的结构体中。

---

## Cite

- Page: https://zeli.app/zh/story/48879529
- Date: 2026-07-12
- Source: antoine.vandecreme.net (https://antoine.vandecreme.net/blog/exhaustive-destructuring-praise/)
- Hacker News: https://news.ycombinator.com/item?id=48879529

## Other languages

- en: https://zeli.app/story/48879529 · markdown: https://zeli.app/story/48879529.md
- ja: https://zeli.app/ja/story/48879529 · markdown: https://zeli.app/ja/story/48879529.md
- ko: https://zeli.app/ko/story/48879529 · markdown: https://zeli.app/ko/story/48879529.md
- de: https://zeli.app/de/story/48879529 · markdown: https://zeli.app/de/story/48879529.md
- es: https://zeli.app/es/story/48879529 · markdown: https://zeli.app/es/story/48879529.md
