0

I'm working on a project that can use either TcpStreams or SslStreams, 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?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
vimalloc
  • 3,869
  • 4
  • 32
  • 45

1 Answers1

1

Turns out there is a solution for this built into the openssl library: openssl::ssl::MaybeSslStream.

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
vimalloc
  • 3,869
  • 4
  • 32
  • 45