-
Notifications
You must be signed in to change notification settings - Fork 91
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
Added Endpoint enum to better encode endpoints for different transport types #68
Conversation
Update: I've removed |
I think it's too early to declare support for all these transport types. IMHO we should start working on at least 1 additional transport and make sure that we can actually support it without big changes in code structure. So imho we should try and implement udp/ipc for example and when we'll be sure that it actually works do all the needed stuff to provide configuration options |
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.
pls see my comments. Currently I would prefer not to merge this
For question 1. We already have a Address error variant https://github.com/zeromq/zmq.rs/blob/master/src/error.rs#L8 IMHO all this errors relate to this class |
@Alexei-Kornienko I'll go ahead and make those changes now. In addition, would you be open to me submitting a separate PR to rename |
Fair enough. I marked the Should I have only the currently supported transport protocal (in this case just tcp) in those enums, or should I add for example Udp too in preparation for adding support for Udp? |
Yes
I would start with TCP only and add other transport types together with respective implementation |
Ok, I've removed all the transport variants except Tcp. |
OK, I ended up doing the error handling changes in this PR because it integrated too closely with the I couldn't trivially use the existing Alternatively, I could modify the PR to get rid of |
LGTM. Could you please rebase your branch before merging? IMHO you could squash some commits to make history clean and nice |
@Alexei-Kornienko OK, I've rebased and fixed up some of the commits to distill it down to the two main contributions. Merge when ready |
I've added an
Endpoint
enum, along with aHost
andTransport
enum. These enums should help us add support for new transport types other than tcp or udp.Without the enums, I found myself having to check the syntax of the string based endpoint a lot. For example, if its tcp the string should be host:port, but if its ipc it should just be a string address. By consolidating all of these checks into the parse() method of
Endpoint
, we can avoid scattering these parsing and checking steps everywhere in the code, and we can also let people avoid that overhead by directly constructing the Endpoint.Things to discuss:
endpoint
module yet - most of them are labeled asZmqError::Other
. What do you recommend the error type be?I have made a custom trait calledTryIntoEndpoint
which basically does the same thing asTryInto<Endpoint, Error=ZmqError>
. I have the trait because I wanted something similar to a trait alias, but that isn't a thing in rust yet (see Tracking issue for trait aliases rust-lang/rust#41517). Is this the right approach?I currently accept arguments asa: impl TryIntoEndpoint
for the user-facing functions accepting an endpoint. This form of static dispatch will get monomorphized in most cases and lead to code bloat, but lets the user pass either strings orEndpoint
types to these functions, which is a little more ergonomic. However, its really not that hard to pass the argument as"tcp://example.com:4567".parse()
. It might be worth removing theimpl TryIntoEndpoint
and just doinga: Endpoint
instead. That might also let us delete theTryIntoEndpoint
trait entirely, and will lead to faster compile times and smaller binary sizes. Especially if we intend to support WASM as a platform, where binary size really matters, this will be important. What are your thoughts?Endpoint
enum are currently just tuples. For example, I haveEndpoint::Tcp(Host, Port)
. This means that if there are functions that operate exclusively on a particular type of endpoint (lets sayTcpEndpoint
), we currently have to do a match to make sure that we have the right transport type for any givenEndpoint
. It might be worth instead making each variant of theEndpoint
have a type. For example, we could have bothEndpoint
andTcpEndpoint
, whereTcpEndpoint
is a tuple struct of(Host, Port)
, and we would haveEndpoint::Tcp(TcpEndpoint)
. We could alsoimpl From<TcpEndpoint> for Endpoint
to allow to easily convert from a TcpEndpoint to an Endpoint. The only downside is that it would introduce a lot of additional types, but I think that its worth it for the increase in type safety