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 })
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM