diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-27 10:07:48 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-27 10:07:48 -0700 |
| commit | 88c3a0f423ea99be1e835b0dc24d3dcd5306a307 (patch) | |
| tree | 6c6680668ba2f85f8e0dc7af7115156857b0fd89 /src/libstd/net | |
| parent | 5d8a5297dafd4cba47b04b6ccd6ac98d141b89d7 (diff) | |
| parent | 1c43e53c8ffe672a041850c25471e32a926e2314 (diff) | |
| download | rust-88c3a0f423ea99be1e835b0dc24d3dcd5306a307.tar.gz rust-88c3a0f423ea99be1e835b0dc24d3dcd5306a307.zip | |
rollup merge of #23750: murarth/ipaddr-fromstr
Diffstat (limited to 'src/libstd/net')
| -rw-r--r-- | src/libstd/net/parser.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/libstd/net/parser.rs b/src/libstd/net/parser.rs index e7509834c7b..7c1667a603f 100644 --- a/src/libstd/net/parser.rs +++ b/src/libstd/net/parser.rs @@ -16,7 +16,7 @@ use prelude::v1::*; use str::FromStr; -use net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; +use net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; struct Parser<'a> { // parsing as ASCII, so can use byte array @@ -24,11 +24,6 @@ struct Parser<'a> { pos: usize, } -enum IpAddr { - V4(Ipv4Addr), - V6(Ipv6Addr), -} - impl<'a> Parser<'a> { fn new(s: &'a str) -> Parser<'a> { Parser { @@ -296,6 +291,17 @@ impl<'a> Parser<'a> { } } +#[unstable(feature = "ip_addr", reason = "recent addition")] +impl FromStr for IpAddr { + type Err = AddrParseError; + fn from_str(s: &str) -> Result<IpAddr, AddrParseError> { + match Parser::new(s).read_till_eof(|p| p.read_ip_addr()) { + Some(s) => Ok(s), + None => Err(AddrParseError(())) + } + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl FromStr for Ipv4Addr { type Err = AddrParseError; |
