How to specify a return type if it is behind a private module?

Viewed 88
fn connect_tls() -> Result<rustls::stream::Stream<rustls::client::ClientSession, TcpStream>, Box<dyn Error>> {}

gives

module `stream` is private

private module

module `client` is private

private module

Can the type somehow be inferred?

1 Answers

The modules client and stream are private, but client::ClientSession and stream::Stream are both exported by the rustls crate at the top level. You should be able to just write this as:

fn connect_tls() -> Result<rustls::Stream<rustls::ClientSession, TcpStream>, Box<dyn Error>> {}

The documentation for rustls doesn't mention those private modules at all, so you will be just fine by using types as shown in the docs.

Related