Skip to content
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

Implement conversion traits for IpAddr #1816

Closed
Yamakaky opened this issue Dec 12, 2016 · 6 comments
Closed

Implement conversion traits for IpAddr #1816

Yamakaky opened this issue Dec 12, 2016 · 6 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Comments

@Yamakaky
Copy link

I'm thinking From<Ipv4Addr> and From<Ipv6Addr> at least.

@sfackler
Copy link
Member

These seem pretty straightforward - feel free to open a PR adding them!

@seanmonstar
Copy link
Contributor

I know I've often times wanted an easy way to create an SocketAddr without going through FromStr. There is a new constructor, but building an IpAddr is cumbersome. Maybe with From<[u8; 4]> or From<(u8, u8, u8, u8)>, or maybe as a new constructor on IpAddr.

I've wanted to reach for something like this, since it only requires the single SocketAddr import:

let addr = SocketAddr::new((127, 0, 0, 1), 8080);

But it would require changing SocketAddr::new to accept <T: Into<IpAddr>>...

@mattico
Copy link

mattico commented Dec 13, 2016

A related (?) conversion which I think would be too confusing as a From impl would be converting IPv4 addresses to IPv6 mapped addresses (see https://tools.ietf.org/html/rfc4291 2.5.5.2). Perhaps .to_v6() or .to_mapped() or .to_ipv6_mapped_addr()? The shorter names may be confusing if you don't read the doc description, but so is most of the standard library.

@nrc nrc added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Dec 19, 2016
Yamakaky added a commit to Yamakaky/rust that referenced this issue Dec 25, 2016
@frewsxcv
Copy link
Member

@mattico Interesting idea. It might be worth opening a separate issue for that so it can have its own separate discussion

@frewsxcv
Copy link
Member

frewsxcv commented Dec 28, 2016

@mattico FYI, these methods already exist (I didn't know they existed until now):

Considering there are multiple ways to convert, adding a single From<IpV4> for IpV6 wouldn't be straightforward.

bors added a commit to rust-lang/rust that referenced this issue Jan 7, 2017
Impl From<Ipv4Addr, Ipv6Addr> for IpAddr.

Fixes rust-lang/rfcs#1816.
@Yamakaky
Copy link
Author

Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

6 participants