用私有模块类型定义结构成员

时间:2019-10-25 23:12:35

标签: rust

我一直在使用一堆具有build()函数并返回结构的模块。但是,当我尝试创建自己的“超级”结构将它们捆绑在一起时,我遇到了错误module `xxx` is private rustc(E0603)。如果有特征,我可以将单个变量作为参数传递,但不能弄清楚如何为结构定义/装箱。

我遇到的当前示例是在创建超级客户端时。

// Error due to privacy and cannot use the trait to define the member type
// Both the "hyper_rustls::connector" and "hyper::client::connect::http" modules are private.
struct SecureClient {
    client: hyper::client::Client<
                hyper_rustls::connector::HttpsConnector<hyper::client::connect::http::HttpConnector>> 
}

// Works, but passing the client everywhere as an individual variable is not realistic.
fn use_client(client: hyper::client::Client<impl hyper::client::connect::Connect>) -> () {
    ()
}

let https_conn = hyper_rustls::HttpsConnector::new(4);
let client: hyper::client::Client<_, hyper::Body> = hyper::Client::builder().build(https_conn);

作为Rust的新手,我正在努力弄清楚什么才是我要尝试的行话,更不用说使它行之有效了。链接到任何与此有关的文档或代码示例。

谢谢

1 个答案:

答案 0 :(得分:0)

我不确定您要做什么,但是您可以使用公共重新导出hyper_rustls::HttpsConnector代替私有hyper_rustls::connector::HttpsConnector,使用公共重新导出hyper::client::HttpConnector代替私人hyper::client::connect::http::HttpConnector。 您可以在这里阅读有关转口的信息:https://doc.rust-lang.org/book/ch07-04-bringing-paths-into-scope-with-the-use-keyword.html#re-exporting-names-with-pub-use

相关问题