一,目前這個需要安裝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 }) }