cargo inspect
1.0.0
该板条箱由货物销售升级,这为我们开始在货物检查时所缺少的所有功能提供了支持。感谢所有人的反馈和支持。
只有两种方法可以生活。
一个好像没有什么是奇迹。另一个似乎一切都是奇迹。 - 阿尔伯特·爱因斯坦
您需要每晚生锈和rustfmt才能开始。
您可以通过Rustup安装它们:
rustup install nightly
rustup component add rustfmt
全部设置?让我们开始破解!
cargo install cargo-inspect
在任何生锈文件上称呼它:
cargo inspect main.rs
如果您不指定文件,则将分析当前的板条箱。
cargo inspect
根据板条箱的大小,这可能需要一段时间。
请耐心等待。
它还可以比较两个文件输出!尝试以下操作:
cargo inspect --diff examples/range.rs,examples/range_inclusive.rs --plain
USAGE:
cargo inspect [FLAGS] [OPTIONS] [INPUT_FILE]
FLAGS:
-h, --help
Prints help information
--list-themes
Should we list all pretty printer themes?
--plain
Don't highlight output
-V, --version
Prints version information
-v, --verbose
Print the original code as a comment above the desugared code
OPTIONS:
--theme <THEME>
Specify a theme override for the pretty printer
--diff <files>
Diff input files
--format <format>
Override for the format that gets outputted when the `unpretty` mode is set to `flowgraph` [default: svg]
--unpretty <unpretty>
rustc "unpretty" parameters
*Note*: For `--unpretty=flowgraph=[symbol]` you need to have `dot` on your PATH. [default: hir]
ARGS:
<INPUT_FILE>
Input file
Rust允许大量的句法糖,这使得写作很高兴。但是,有时很难看窗帘后面,看看编译器对我们的代码的真正作用。
引用@tshepang的话说:“很高兴知道这些便利是什么,避免被引擎盖下发生的事情感到迷惑……我们对世界的魔力越小,越好。”
我一直对编程语言在后台工作,如何展开我的代码以使编译器后端更易于维护。
目的是使编译器更容易成为凡人。
神秘!勘探!发现!
在我的博客上阅读cargo-inspect的背景的更多信息。
If-let被删除参加match考虑以下代码段:
fn main ( ) {
if let Some ( x ) = Some ( 1 ) {
// Do something with x
}
}当您编译它时,Rust所做的第一件事就是Desugar。要查看此步骤之后的代码的样子,请运行
cargo inspect examples/if_let.rs
这会产生以下输出:
请在examples文件夹中找到更多示例。您也可以做出更多贡献。
世界上最好的事情是由简单的构建块组装而成的。该工具站在巨人的肩膀上。为了发挥其魔力,它运行以下命令:
rustc -Zinspect=hir ,用于检索Hir。rustfmt ,用于格式化输出。prettyprint ,用于语法高光,这只是围绕令人敬畏的语法和蝙蝠板条箱的包装。 这是一个年轻的项目,它具有不利影响和优势。
因此,成为今天的贡献者!
截至目前,这是一个非常脆弱的工具。如果失败,可能将产生可怕的输出。您已经被警告。也就是说,当然不会吃您的代码。 ?
根据任何一个
可以选择。
由RawPixel.com设计的放大镜