温馨提示:本文翻译自stackoverflow.com,查看原文请点击:rust - How can I forward/alias/delegate a function to a method?
rust

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

发布于 2020-03-29 12:50:49

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

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>> { ... }

}

查看更多

查看更多

提问者
Matt Joiner
被浏览
92
Stargateur 2020-01-30 08:43

Rust无法做到这一点。