cargo expand用于查看被宏隐藏的代码
目录
一,目前这个需要安装nightly的toolchain,rustup toolchain install nightly-x86_64-unknown-linux-gnu
二,用这个命令安装:cargo +nightly install cargo-expand
三,到具体的项目里去,比如demo-01项目,然后用了tide和async-std,只有一个代码文件为:

use std::result::Result;
#[async_std::main]
async fn main() -> Result<(), std::io::Error>{
println!("Hello, world!");
Ok(())
}

这里我一直不知道#[async_std::main]到底是干嘛用的,而且之前一直以为这个是async-std提供的功能,现在才发现是tide提供的宏(其他框架可能也提供了类似的);
四,运行cargo expand --bin demo-01来展开被宏隐藏的代码,得到:

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
use std::result::Result;
fn main() -> Result<(), std::io::Error> {
async fn main() -> Result<(), std::io::Error> {
{
{
::std::io::_print(::core::fmt::Arguments::new_v1(
&["Hello, world!\n"],
&match () {
() => [],
},
));
};
Ok(())
}
}
async_std::task::block_on(async { main().await })
}

作者:Silentdoer
欢迎任何形式的转载,但请务必注明出处。
限于本人水平,如果随笔/文章及代码有表述不当之处,还请不吝赐教。
赞 (0)
