-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
A few ergonomic From impls for SocketAddr/IpAddr #39372
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
I wonder if something like impl<T: Into<Ipv4Addr>> From<T> for IpAddr { ... } would be at odds with the coherence. |
@nagisa I considered it, but also worried about the possibility of some type |
For completion, can you add implementations for |
@clarcharr implementations for |
I worry slightly that this seems "too clever" but we've got precedent elsewhere in the standard library for working with @rfcbot fcp merge |
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This is cool! 👍 from me. |
src/libstd/net/ip.rs
Outdated
|
||
#[stable(feature = "ip_from_slice", since = "1.17.0")] | ||
impl From<[u16; 8]> for IpAddr { | ||
fn from(octets: [u16; 8]) -> IpAddr { |
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.
Tiny correction: this should say segments
instead of octects
.
63cb2ad
to
cd603e4
Compare
ping @BurntSushi, @brson (checkboxes) |
@bors: r+ |
📌 Commit cd603e4 has been approved by |
…crichton A few ergonomic From impls for SocketAddr/IpAddr My main motivation is removing things like this: `"127.0.0.1:3000".parse().unwrap()`. Instead, this now works: `SocketAddr::from(([127, 0, 0, 1], 3000))` or even `([127, 0, 0, 1], 3000).into())` when passing to a function.
…crichton A few ergonomic From impls for SocketAddr/IpAddr My main motivation is removing things like this: `"127.0.0.1:3000".parse().unwrap()`. Instead, this now works: `SocketAddr::from(([127, 0, 0, 1], 3000))` or even `([127, 0, 0, 1], 3000).into())` when passing to a function.
My main motivation is removing things like this:
"127.0.0.1:3000".parse().unwrap()
. Instead, this now works:SocketAddr::from(([127, 0, 0, 1], 3000))
or even([127, 0, 0, 1], 3000).into())
when passing to a function.