外观
内置 API 篇:标准库是你的百宝箱
小螃蟹说
真实项目里,你会惊讶地发现:一半的"难题",标准库早就替你想好了——你只是不知道方法名。
这一篇,我们把标准库里最高频、最容易"不知道有它"的 API 逐个过一遍:每个方法给真实场景 + 常见误用 + 正确写法。不背 API 列表,而是"原来还能这样"的顿悟集。
建议:当查询手册用——写代码卡住时,先翻这一篇,再上网搜。
这一篇的内容
| 节 | 主题 | 你会拿到什么 |
|---|---|---|
| 1 | Option 方法宝库 | map/and_then/unwrap_or/take/filter 场景 |
| 2 | Result 方法宝库 | and_then/or_else/map_err/is_err/inspect |
| 3 | 迭代器冷门方法 | zip/fold/partition/scan/chain/take_while |
| 4 | String 高频 API | split 家族/trim/replace/repeat/lines |
| 5 | Vec 高频 API | extend/retain/dedup/windows/chunks/swap_remove |
| 6 | HashMap 高频 API | entry 全家/and_modify/remove/retain/get_key_value |
| 7 | 时间与计时 | Instant/Duration/SystemTime 计时与格式化 |
| 8 | 文件系统 fs 与 Path | read_dir/write/remove/Path 拼接与判断 |
约定
这一篇的代码都短小独立,方便你直接复制到自己的项目里试。每个方法标注"⭐ 高频"或"✨ 冷门但好用"。