Silentdoer

导航

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来展开被宏隐藏的代码,得到:【这种方式不好,可以直接expand单个文件:cargo expand model::student > src/model/student_expanded.rs(注意在项目根目录下执行,这里model是src下的目录,student是model下的student.rs)】

#![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 })
}

 

posted on 2020-07-05 11:34  Silentdoer  阅读(1807)  评论(0编辑  收藏  举报