Reputation: 4177
I'm working on a project that can use either TcpStream
s or SslStream
s, depending on what the user configured. I have a few simple methods such as send_cmd(stream)
and recv_msg(stream)
which operates on these streams.
Would it be more idiomatic to create an enum that could be either TcpStream
or SslStream
and pass that to these methods? Or would it be better to do something with traits, such as requiring the stream argument to these methods implement the Read
and Write
traits?
My thought is that the enum solution would be better, as it explicitly says what kind of data we expect to be handling instead of allowing for anything that implements Read
or Write
, such as files. On the flip side though, it would require a match on all of these methods before using the stream. Thoughts?
Upvotes: 0
Views: 352
Reputation: 4177
Turns out there is a solution for this built into the openssl library: openssl::ssl::MaybeSslStream
.
Upvotes: 1