将RUST的宏扩展输出到文件中读取
今天尝试一下tonic框架,想要运行一下examples里面的streaming,尝试一下全双工通讯,但是client代码中遇到的以下代码很显然是从macro中扩展出来的
pub mod pb {
tonic::include_proto!("grpc.examples.echo");
}
...
use pb::{echo_client::EchoClient, EchoRequest};
所以想要输出这个include_proto!到底扩展了什么,根据stackoverflow的提示我如下操作:
#先下载一下代码扩展工具
cargo install cargo-expand
#然后你就可以在examples目录底下把你想要获得的扩展后的rust文件输出了
cargo expand --bin streaming-client > expanded.rs
宏扩展的部分结果如下
pub mod pb {
/// EchoRequest is the request for echo.
#[allow(clippy::derive_partial_eq_without_eq)]
pub struct EchoRequest {
#[prost(string, tag = "1")]
pub message: ::prost::alloc::string::String,
}
#[automatically_derived]
#[allow(clippy::derive_partial_eq_without_eq)]
impl ::core::clone::Clone for EchoRequest {
#[inline]
fn clone(&self) -> EchoRequest {
EchoRequest {
message: ::core::clone::Clone::clone(&self.message),
}
}
}
...
/// Generated client implementations.
pub mod echo_client {
...
}
/// Generated server implementations.
pub mod echo_server {
...
}
}