Warm tip: This article is reproduced from stackoverflow.com, please click
rust

How can I forward/alias/delegate a function to a method?

发布于 2020-03-29 12:45:59

I want to forward a function to a method in another module, without repeating all the type annotations, and without manually passing the parameters over. How would I do this?

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

}
Questioner
Matt Joiner
Viewed
73
Stargateur 2020-01-30 08:43

There is no way to do that in Rust.