Skip to content

Commit

Permalink
Use Ipv4Addr::from<[u8; 4]> when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Jun 16, 2020
1 parent f315c35 commit 0e6c333
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/libstd/sys/hermit/net.rs
Expand Up @@ -147,10 +147,7 @@ impl TcpStream {
.map_err(|_| io::Error::new(ErrorKind::Other, "peer_addr failed"))?;

let saddr = match ipaddr {
Ipv4(ref addr) => SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(addr.0[0], addr.0[1], addr.0[2], addr.0[3])),
port,
),
Ipv4(ref addr) => SocketAddr::new(IpAddr::V4(Ipv4Addr::from(addr.0)), port),
Ipv6(ref addr) => SocketAddr::new(IpAddr::V6(Ipv6Addr::from(addr.0)), port),
_ => {
return Err(io::Error::new(ErrorKind::Other, "peer_addr failed"));
Expand Down Expand Up @@ -227,10 +224,7 @@ impl TcpListener {
let (handle, ipaddr, port) = abi::tcplistener::accept(self.0.port())
.map_err(|_| io::Error::new(ErrorKind::Other, "accept failed"))?;
let saddr = match ipaddr {
Ipv4(ref addr) => SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(addr.0[0], addr.0[1], addr.0[2], addr.0[3])),
port,
),
Ipv4(ref addr) => SocketAddr::new(IpAddr::V4(Ipv4Addr::from(addr.0)), port),
Ipv6(ref addr) => SocketAddr::new(IpAddr::V6(Ipv6Addr::from(addr.0)), port),
_ => {
return Err(io::Error::new(ErrorKind::Other, "accept failed"));
Expand Down

0 comments on commit 0e6c333

Please sign in to comment.