Skip to content

Commit 88c3a0f

Browse files
committed
rollup merge of #23750: murarth/ipaddr-fromstr
2 parents 5d8a529 + 1c43e53 commit 88c3a0f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/libstd/net/parser.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,14 @@
1616
use prelude::v1::*;
1717

1818
use str::FromStr;
19-
use net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
19+
use net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
2020

2121
struct Parser<'a> {
2222
// parsing as ASCII, so can use byte array
2323
s: &'a [u8],
2424
pos: usize,
2525
}
2626

27-
enum IpAddr {
28-
V4(Ipv4Addr),
29-
V6(Ipv6Addr),
30-
}
31-
3227
impl<'a> Parser<'a> {
3328
fn new(s: &'a str) -> Parser<'a> {
3429
Parser {
@@ -296,6 +291,17 @@ impl<'a> Parser<'a> {
296291
}
297292
}
298293

294+
#[unstable(feature = "ip_addr", reason = "recent addition")]
295+
impl FromStr for IpAddr {
296+
type Err = AddrParseError;
297+
fn from_str(s: &str) -> Result<IpAddr, AddrParseError> {
298+
match Parser::new(s).read_till_eof(|p| p.read_ip_addr()) {
299+
Some(s) => Ok(s),
300+
None => Err(AddrParseError(()))
301+
}
302+
}
303+
}
304+
299305
#[stable(feature = "rust1", since = "1.0.0")]
300306
impl FromStr for Ipv4Addr {
301307
type Err = AddrParseError;

0 commit comments

Comments
 (0)