-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Abstract over NetworkStream using dynamic dispatch #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
c3aaaaa
to
b32a7e9
Compare
cc #17 |
This introduces a new Trait, NetworkStream, which abstracts over the functionality provided by TcpStream so that it can be easily mocked and extended in testing and hyper can be used for other connection sources.
src/server/request.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you want this to be boxed also, removing the generic? Or purposefully left alone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, my bad. I completely forgot to change anything but the server response :/
Server and client benchmarks show that this makes very little difference in performance and using dynamic dispatch here is significantly more ergonomic. This also bounds NetworkStream with Send to prevent incorrect implementations. Allows the implementation of mock streams for testing and flexibility. Fixes hyperium#5
…orkStream> Also adds a convenience `abstract` method to NetworkStream for creating Box<NetworkStream + Send> from a NetworkStream.
…g generics The client benchmarks did not have to be changed at all for this whole refactor, and the server benchmark only had to specify a single type parameter, and only because it writes out the type of Listener, which is not normal usage.
6bad66a
to
632250b
Compare
@seanmonstar Updated. |
Abstract over NetworkStream using dynamic dispatch
Abstract out NetworkStream for testing and extensibility, but use dynamic
dispatch to maintain ergonomics and not have a flood of generics.
Server and client benchmarks show that this makes very little difference in
performance and using dynamic dispatch here is significantly more
ergonomic.
This also bounds NetworkStream with Send to prevent incorrect
implementations.
@seanmonstar I checkout out your branch, rebased current master,
and then made these changes.