Skip to content

Implement FromStr for IpAddr and SocketAddr #8336

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

Closed
wants to merge 2 commits into from

Conversation

stepancheg
Copy link
Contributor

FromStr implemented from scratch.

It is overengineered a bit, however.

Old implementation handles errors by fail!()-ing. And it has bugs, like it accepts 127.0.0.1::127.0.0.1 as IPv6 address, and does not handle all ipv4-in-ipv6 schemes. So I decided to implement parser from scratch.

Better than that in rt::uv::net, because it:

* handles invalid input explicitly, without fail!()
* parses socket address, not just IP
* handles various ipv4-in-ipv6 addresses, like 2001:db8:122:344::192.0.2.33
  (see http://tools.ietf.org/html/rfc6052 for example)
* rejects output like `127.0000000.0.1`
* does not allocate heap memory
* have unit tests
}

// Commit only if parser returns Some
fn read_atomially<T>(&mut self, cb: &fn(&mut Parser) -> Option<T>) -> Option<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI, small spelling mistake here: "read_atomially" should be "read_atomically".

@stepancheg
Copy link
Contributor Author

Fixed typo in method name, thanks to @andrew-d.

@luqmana
Copy link
Member

luqmana commented Aug 6, 2013

Awesome! Mind also fixing a mistake in ToStr?

https://github.com/stepancheg/rust/blob/58b11229e563da705e2579821b8c3fe1fa799c52/src/libstd/rt/io/net/ip.rs#L46 should be Ipv6Addr(0, 0, 0, 0, 0, 0xFFFF, g, h).

@stepancheg
Copy link
Contributor Author

@luqmana thank you for the bugreport, created pull request #8352.

bors added a commit that referenced this pull request Aug 9, 2013
FromStr implemented from scratch.

It is overengineered a bit, however.

Old implementation handles errors by fail!()-ing. And it has bugs, like it accepts `127.0.0.1::127.0.0.1` as IPv6 address, and does not handle all ipv4-in-ipv6 schemes. So I decided to implement parser from scratch.
@bors bors closed this Aug 9, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 6, 2022
[`needless_return`] Recursively remove unneeded semicolons

fix rust-lang#8336,
fix rust-lang#8156,
fix rust-lang/rust-clippy#7358,
fix rust-lang#9192,
fix rust-lang/rust-clippy#9503

changelog: [`needless_return`] Recursively remove unneeded semicolons

For now the suggestion about removing the semicolons are hidden because they would be very noisy and should be obvious if the user wants to apply the lint manually instead of using `--fix`. This could be an issue for beginner, but haven't found better way to display it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants