Change:
I need to parse an ipv4 address. I feel like these impls are missing seeing as we have impls of for , and .

Discussion:
fn test_from_str_socket_addr() { assert_eq!(Ok(sa4(Ipv4Addr::new(77, 88, 21, 11), 80)), "77.88.21.11:80".parse()); <ins> assert_eq!(Ok(SocketAddrV4::new(Ipv4Addr::new(77, 88, 21, 11), 80)), "77.88.21.11:80".parse()); </ins> assert_eq!(Ok(sa6(Ipv6Addr::new(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), 53)), "[2a02:6b8:0:1::1]:53".parse()); <ins> assert_eq!(Ok(SocketAddrV6::new(Ipv6Addr::new(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), 53, 0, 0)), "[2a02:6b8:0:1::1]:53".parse()); </ins> assert_eq!(Ok(sa6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x7F00, 1), 22)), "[::127.0.0.1]:22".parse()); <ins> assert_eq!(Ok(SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x7F00, 1), 22, 0, 0)), "[::127.0.0.1]:22".parse()); </ins> // without port let none: Option<SocketAddr> = "127.0.0.1".parse().ok();

self.read_or(&mut [Box::new(ipv4_addr), Box::new(ipv6_addr)]) } <del> fn read_socket_addr(&mut self) -> Option<SocketAddr> { </del> <ins> fn read_socket_addr_v4(&mut self) -> Option<SocketAddrV4> { let ip_addr = |p: &mut Parser| p.read_ipv4_addr(); let colon = |p: &mut Parser| p.read_given_char(':'); let port = |p: &mut Parser| { p.read_number(10, 5, 0x10000).map(|n| n as u16) }; self.read_seq_3(ip_addr, colon, port).map(|t| { let (ip, _, port): (Ipv4Addr, char, u16) = t; SocketAddrV4::new(ip, port) }) } fn read_socket_addr_v6(&mut self) -> Option<SocketAddrV6> { </ins> let ip_addr = |p: &mut Parser| { <del> let ipv4_p = |p: &mut Parser| p.read_ip_addr(); let ipv6_p = |p: &mut Parser| { let open_br = |p: &mut Parser| p.read_given_char('['); let ip_addr = |p: &mut Parser| p.read_ipv6_addr(); let clos_br = |p: &mut Parser| p.read_given_char(']'); p.read_seq_3::<char, Ipv6Addr, char, _, _, _>(open_br, ip_addr, clos_br) .map(|t| match t { (_, ip, _) => IpAddr::V6(ip) }) }; p.read_or(&mut [Box::new(ipv4_p), Box::new(ipv6_p)]) </del> <ins> let open_br = |p: &mut Parser| p.read_given_char('['); let ip_addr = |p: &mut Parser| p.read_ipv6_addr(); let clos_br = |p: &mut Parser| p.read_given_char(']'); p.read_seq_3(open_br, ip_addr, clos_br).map(|t| t.1) </ins> }; let colon = |p: &mut Parser| p.read_given_char(':'); <del> let port  = |p: &mut Parser| p.read_number(10, 5, 0x10000).map(|n| n as u16); </del> <ins> let port = |p: &mut Parser| { p.read_number(10, 5, 0x10000).map(|n| n as u16) }; </ins> <del> // host, colon, port </del> self.read_seq_3(ip_addr, colon, port).map(|t| { <del> let (ip, _, port): (IpAddr, char, u16) = t; match ip { IpAddr::V4(ip) => SocketAddr::V4(SocketAddrV4::new(ip, port)), IpAddr::V6(ip) => SocketAddr::V6(SocketAddrV6::new(ip, port, 0, 0)), } </del> <ins> let (ip, _, port): (Ipv6Addr, char, u16) = t; SocketAddrV6::new(ip, port, 0, 0) </ins> }) } <ins> fn read_socket_addr(&mut self) -> Option<SocketAddr> { let v4 = |p: &mut Parser| p.read_socket_addr_v4().map(SocketAddr::V4); let v6 = |p: &mut Parser| p.read_socket_addr_v6().map(SocketAddr::V6); self.read_or(&mut [Box::new(v4), Box::new(v6)]) } </ins> } #[stable(feature = "rust1", since = "1.0.0")]

} } <ins> #[stable(feature = "socket_addr_from_str", since = "1.5.0")] impl FromStr for SocketAddrV4 { type Err = AddrParseError; fn from_str(s: &str) -> Result<SocketAddrV4, AddrParseError> { match Parser::new(s).read_till_eof(|p| p.read_socket_addr_v4()) { Some(s) => Ok(s), None => Err(AddrParseError(())), } } } #[stable(feature = "socket_addr_from_str", since = "1.5.0")] impl FromStr for SocketAddrV6 { type Err = AddrParseError; fn from_str(s: &str) -> Result<SocketAddrV6, AddrParseError> { match Parser::new(s).read_till_eof(|p| p.read_socket_addr_v6()) { Some(s) => Ok(s), None => Err(AddrParseError(())), } } } </ins> #[stable(feature = "rust1", since = "1.0.0")] impl FromStr for SocketAddr { type Err = AddrParseError;