diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-18 20:08:15 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-18 20:10:15 -0700 |
| commit | f2e3c7469b56cd744e613a05a1ea73f441f66401 (patch) | |
| tree | 196e93adf0f0e41ce0d7acf5bced811abebeded0 /src/libstd | |
| parent | 46f649c479ce40f3b4590590dda6c2895e8d60f6 (diff) | |
| download | rust-f2e3c7469b56cd744e613a05a1ea73f441f66401.tar.gz rust-f2e3c7469b56cd744e613a05a1ea73f441f66401.zip | |
std: Stabilize FromStr implementations in std::net
The IP and socket address types all had `FromStr` implemented but the implementations were not marked stable, nor was the error type returned ready to be properly stabilized. This commit marks the implementations of `FromStr` as stable and also renamed the `ParseError` structure to `AddrParseError`. The error is now also an opaque structure that cannot be constructed outside the standard library. cc #22949 [breaking-change]
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/net/mod.rs | 1 | ||||
| -rw-r--r-- | src/libstd/net/parser.rs | 27 |
2 files changed, 17 insertions, 11 deletions
diff --git a/src/libstd/net/mod.rs b/src/libstd/net/mod.rs index 36f36af73e1..543fdd16f41 100644 --- a/src/libstd/net/mod.rs +++ b/src/libstd/net/mod.rs @@ -25,6 +25,7 @@ pub use self::ip::{Ipv4Addr, Ipv6Addr, Ipv6MulticastScope}; pub use self::addr::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs}; pub use self::tcp::{TcpStream, TcpListener}; pub use self::udp::UdpSocket; +pub use self::parser::AddrParseError; mod ip; mod addr; diff --git a/src/libstd/net/parser.rs b/src/libstd/net/parser.rs index 9843a152718..e7509834c7b 100644 --- a/src/libstd/net/parser.rs +++ b/src/libstd/net/parser.rs @@ -296,35 +296,40 @@ impl<'a> Parser<'a> { } } +#[stable(feature = "rust1", since = "1.0.0")] impl FromStr for Ipv4Addr { - type Err = ParseError; - fn from_str(s: &str) -> Result<Ipv4Addr, ParseError> { + type Err = AddrParseError; + fn from_str(s: &str) -> Result<Ipv4Addr, AddrParseError> { match Parser::new(s).read_till_eof(|p| p.read_ipv4_addr()) { Some(s) => Ok(s), - None => Err(ParseError) + None => Err(AddrParseError(())) } } } +#[stable(feature = "rust1", since = "1.0.0")] impl FromStr for Ipv6Addr { - type Err = ParseError; - fn from_str(s: &str) -> Result<Ipv6Addr, ParseError> { + type Err = AddrParseError; + fn from_str(s: &str) -> Result<Ipv6Addr, AddrParseError> { match Parser::new(s).read_till_eof(|p| p.read_ipv6_addr()) { Some(s) => Ok(s), - None => Err(ParseError) + None => Err(AddrParseError(())) } } } +#[stable(feature = "rust1", since = "1.0.0")] impl FromStr for SocketAddr { - type Err = ParseError; - fn from_str(s: &str) -> Result<SocketAddr, ParseError> { + type Err = AddrParseError; + fn from_str(s: &str) -> Result<SocketAddr, AddrParseError> { match Parser::new(s).read_till_eof(|p| p.read_socket_addr()) { Some(s) => Ok(s), - None => Err(ParseError), + None => Err(AddrParseError(())), } } } -#[derive(Debug, Clone, PartialEq, Copy)] -pub struct ParseError; +/// An error returned when parsing an IP address or a socket address. +#[stable(feature = "rust1", since = "1.0.0")] +#[derive(Debug, Clone, PartialEq)] +pub struct AddrParseError(()); |
