用于显示宏展开结果的子命令
安装后,以下命令会打印出应用于当前 crate 的宏展开和 #[derive] 展开的结果。
$ cargo expand这是对更冗长的编译器命令的封装:
$ cargo rustc --profile=check -- -Zunpretty=expanded使用 cargo install cargo-expand 安装。
此命令可选地使用 [rustfmt] 来格式化展开后的输出。生成的代码通常比编译器直接输出的更易读。如果 rustfmt 不可用,展开的代码将不会被格式化。使用 rustup component add rustfmt 安装 rustfmt。
$ cat src/main.rs#[derive(Debug)]
struct S;
fn main() {
println!("{:?}", S);
}$ cargo expand…查看 cargo expand --help 以获取完整的选项列表,其中大部分与其他 Cargo 子命令一致。以下是在 cargo expand 上下文中常见的几个选项。
要展开特定的测试目标:
$ cargo expand --test test_something
要跳过 rustfmt 进行展开:
$ cargo expand --ugly
仅展开特定的模块、类型或函数:
$ cargo expand path::to::module
[![cargo expand punctuated::printing][punctuated.png]][syn] [![cargo expand token::FatArrow][fatarrow.png]][syn]
cargo expand 命令会读取 $CARGO_HOME/config.toml 中的 [expand] 部分(如果存在的话,通常是 ~/.cargo/config.toml)。
使用 theme 设置来配置默认的语法高亮主题:
theme = "TwoDark"运行 cargo expand --themes 或 bat --list-themes 可打印可用主题列表。使用 theme = "none" 可禁用着色。
更改默认着色。
[rustfmt]: https://github.com/rust-lang/rustfmt [punctuated.png]: https://raw.githubusercontent.com/dtolnay/cargo-expand/screenshots/punctuated.png [fatarrow.png]: https://raw.githubusercontent.com/dtolnay/cargo-expand/screenshots/fatarrow.png [syn]: https://github.com/dtolnay/syn [expand]
暂无开放 Issues,或尚未同步最近议题。