cargo expand用於檢視被巨集隱藏的程式碼
阿新 • • 發佈:2020-07-05
一,目前這個需要安裝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 }) }