我想将函数转发到另一个模块中的方法,而无需重复所有类型注释,也无需手动传递参数。我该怎么做?
mod other_mod;
static client: other_mod::Client = other_mod::Client::new();
async fn search = client.search; // How to do this here?
mod other_mod
:
pub struct Client();
impl Client {
pub fn new() -> Self {
Self()
}
pub async fn search(&self, query: &str) -> Result<Vec<SearchResultItem>> { ... }
}
Rust无法做到这一点。
我的工作完成了
真可惜 Go也会这样做,但是我认为这仅仅是因为Go不必要地冗长。