Skip to content

Commit 3e43373

Browse files
committed
Rollup merge of rust-lang#23504 - alexcrichton:parse-error-not-unit, r=aturon
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 rust-lang#22949 [breaking-change]
2 parents 4294327 + f2e3c74 commit 3e43373

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

Diff for: src/libstd/net/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub use self::ip::{Ipv4Addr, Ipv6Addr, Ipv6MulticastScope};
2525
pub use self::addr::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
2626
pub use self::tcp::{TcpStream, TcpListener};
2727
pub use self::udp::UdpSocket;
28+
pub use self::parser::AddrParseError;
2829

2930
mod ip;
3031
mod addr;

Diff for: src/libstd/net/parser.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -296,35 +296,40 @@ impl<'a> Parser<'a> {
296296
}
297297
}
298298

299+
#[stable(feature = "rust1", since = "1.0.0")]
299300
impl FromStr for Ipv4Addr {
300-
type Err = ParseError;
301-
fn from_str(s: &str) -> Result<Ipv4Addr, ParseError> {
301+
type Err = AddrParseError;
302+
fn from_str(s: &str) -> Result<Ipv4Addr, AddrParseError> {
302303
match Parser::new(s).read_till_eof(|p| p.read_ipv4_addr()) {
303304
Some(s) => Ok(s),
304-
None => Err(ParseError)
305+
None => Err(AddrParseError(()))
305306
}
306307
}
307308
}
308309

310+
#[stable(feature = "rust1", since = "1.0.0")]
309311
impl FromStr for Ipv6Addr {
310-
type Err = ParseError;
311-
fn from_str(s: &str) -> Result<Ipv6Addr, ParseError> {
312+
type Err = AddrParseError;
313+
fn from_str(s: &str) -> Result<Ipv6Addr, AddrParseError> {
312314
match Parser::new(s).read_till_eof(|p| p.read_ipv6_addr()) {
313315
Some(s) => Ok(s),
314-
None => Err(ParseError)
316+
None => Err(AddrParseError(()))
315317
}
316318
}
317319
}
318320

321+
#[stable(feature = "rust1", since = "1.0.0")]
319322
impl FromStr for SocketAddr {
320-
type Err = ParseError;
321-
fn from_str(s: &str) -> Result<SocketAddr, ParseError> {
323+
type Err = AddrParseError;
324+
fn from_str(s: &str) -> Result<SocketAddr, AddrParseError> {
322325
match Parser::new(s).read_till_eof(|p| p.read_socket_addr()) {
323326
Some(s) => Ok(s),
324-
None => Err(ParseError),
327+
None => Err(AddrParseError(())),
325328
}
326329
}
327330
}
328331

329-
#[derive(Debug, Clone, PartialEq, Copy)]
330-
pub struct ParseError;
332+
/// An error returned when parsing an IP address or a socket address.
333+
#[stable(feature = "rust1", since = "1.0.0")]
334+
#[derive(Debug, Clone, PartialEq)]
335+
pub struct AddrParseError(());

0 commit comments

Comments
 (0)