最近抽时间看完了<<The secrets of Rust tools» 一书, 以下简称tools.
Tools这边书属于入门级别的rust书籍, 一个周末, 每天看3到4个小时可以看完.
整本书分为了好几个小的项目, 每个项目的模式是一样的TDD.
项目
count lines (wc -l)
提到了 BufRead trait用来做入参,
使用collect 把lines() Vec<Result<» 收集为 Result<Vec<»
简单介绍了 anyhow:Result, bail, context等常见用法,
介绍了 assert_cmd crate直接测试 cargo 命令行crate,
简单介绍了clap解析flag等命令行参数, 以及在后面的章节介绍了clap开发 cargo plugin,
logbook (clap, serde)
简单介绍了File的io操作, 以及File open option builder 模式,
介绍了AsRef<Path>参数,方便测试,
如何public lib crate,
介绍Path to PathBuf the From trait, 以及as_ref From AsRef to reference,
使用serde 和serde_json序列化从硬盘读写数据,保持数据
回顾clap 的用法
weather client (reqwest)
简单介绍reqwest blocking模式,
使用httpmock 来mock http server 测试,
使用serde_json的Pointer方法来避免构造中间strct,
使用new type也就是tuple stuct模式来实现单位转换(摄氏度到华氏)
command (std::process::Command, output.stderr, output.stdout)
简单介绍command结构体和常规用法, 使用String::from_utf8_lossy来转化输出
使用std::time::Instant来完成timer tool
借用walkdir crate以及 –manifest-path参数来完成slim工具,
使用clap #[command(bin_name = “cargo”)] 属性来开发cargo plugin