【发布时间】:2019-10-25 23:12:35
【问题描述】:
我一直在使用一堆具有 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 的新手,我正在努力弄清楚我正在尝试做的事情的正确术语是什么,更不用说让它发挥作用了。任何有关此的文档或代码示例的链接将不胜感激。
谢谢
【问题讨论】:
标签: rust