如何将函数转发/别名/委托给方法?

Mat*_*ner 2 rust

我想将一个函数转发到另一个模块中的一个方法,而不重复所有类型注释,也不需要手动传递参数。我该怎么做?

mod other_mod;

static client: other_mod::Client = other_mod::Client::new();

async fn search = client.search; // How to do this here?
Run Code Online (Sandbox Code Playgroud)

mod other_mod

pub struct Client();

impl Client {
    pub fn new() -> Self {
        Self()
    }    

    pub async fn search(&self, query: &str) -> Result<Vec<SearchResultItem>> { ... }

}
Run Code Online (Sandbox Code Playgroud)

Sta*_*eur 5

在 Rust 中没有办法做到这一点。

  • [我的工作已经完成了](https://knowyourmeme.com/memes/my-job-here-is-done) (2认同)