SLMT / telnet-rs

A simple implementation of Telnet in Rust.
MIT License
45 stars 20 forks source link

Support generic streams #2

Closed lux01 closed 6 years ago

lux01 commented 6 years ago

This PR allows users to costruct a new Telnet object without having to implicitly use a TcpStream. This is to allow users to provide their own streams which is useful if they want to, for example, unit test code that interacts with Telnet, or wrap their TcpStream in TLS.

This is accomplished by introducing a new trait Stream which is Read + Write and captures the interface from TcpStream implicitly used by the Telnet client. The cost of this is that stream we now use dynamic dispatch to interact with the stream.

This could be avoided by making Telnet generic over the type of stream but this would change the external interface.

SLMT commented 6 years ago

Great! Thanks for your contribution! I will check it these days.