gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 11:32:19 24 4
gpt4 key购买 nike

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

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 中无法做到这一点。

关于rust - 我如何将函数转发/别名/委托(delegate)给方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59977439/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com