-
Notifications
You must be signed in to change notification settings - Fork 277
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
[feature] #3383: Implement a macro that parses a socket address at compile time #3675
Conversation
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.
Congratulations with your first PR! Nice!
In PR description you say that custom port is not supported. But by looking at the code it looks like it is supported, no?
I forgot the link to an example.. iroha/core/test_network/src/lib.rs Line 598 in 19984d9
Basically, it uses an arbirary expression instead of an integer literal for port. This won't work with the "stringify and parse it" approach |
So what blocks you to undraft this PR? |
Using expressions as port numbers, which is done a lot throughout the codebase & replacing the uses of declarative |
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.
LGTM. Some comments:
-
I wonder, which syntax would you use for expressions interpolation? I have a couple of ideas:
// format-style? socket_addr!("127.0.0.1:{}", port); // something custom? socket_addr!(127.0.0.1:~port);
-
Will you replace all usages of the old macro?
Also, please make meaningful checklist in the PR's description (the current one is template for external contributors, AFAIC). It might make sense to move some TODOs from your description/code there. |
I think it's possible to parse the natural syntax:
Yes, this is what I am planning to do |
Pull Request Test Coverage Report for Build 5473214665
💛 - Coveralls |
There is an option to exclude a certain macro invocations from being formatted, but
I guess we would have to live with this ugly formatting for some time? |
…dress at compile time Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
- rename macro to socket_addr (for consistency with already existing decl macro) - more backticks - fix `SocketAddr` variant names (whoops) - re-export the macro from `iroha_primitives` under a temporary name Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
- keep the "stringify and parse" approach for the IP part, but parse the rest using syn's parsing framework - special-case brackets: they are used to wrap the IPv6 addresses - use colon as a terminator for IPv4 address Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
…the new syntax Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
…hate it) `rustfmt` wants `socket_addr!(127.0.0.1: port);` to be formatted as `socket_addr!(127.0.0 .1: port);`... There is an option to exclude a certain macro invocations from being formatted, but 1) the config option parsing seems broken rust-lang/rustfmt#5816 2) the toolchain used in CI doesn't support it I guess we would have to live with this ugly formatting for some time... Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
Linked issue
Closes #3383
Limitations
This can't replace all uses of the existing
socket_addr!
macro, as it parses only literal addresses. Some of thesocket_addr!
usages use an expression as port number:iroha/core/test_network/src/lib.rs
Line 598 in 19984d9
As 5/11 usages of the original macro use it, it probably doesn't make sense to merge it without support for variable ports
It also doesn't support hostname addresses, but they are not used anywhere except in the doc-test for the
socket_addr!
macro. Probably fine going without it, but should be relatively easy to implement if needed.Checklist
socket_addr!
macro