Skip to content

Commit b61fdde

Browse files
committed
Implement Error for AddrParseError
Closes rust-lang#27973
1 parent 63ba780 commit b61fdde

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/libstd/net/parser.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
1616
use prelude::v1::*;
1717

18-
use str::FromStr;
18+
use error::Error;
19+
use fmt;
1920
use net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
21+
use str::FromStr;
2022

2123
struct Parser<'a> {
2224
// parsing as ASCII, so can use byte array
@@ -339,3 +341,15 @@ impl FromStr for SocketAddr {
339341
#[stable(feature = "rust1", since = "1.0.0")]
340342
#[derive(Debug, Clone, PartialEq)]
341343
pub struct AddrParseError(());
344+
345+
impl fmt::Display for AddrParseError {
346+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
347+
fmt.write_str(self.description())
348+
}
349+
}
350+
351+
impl Error for AddrParseError {
352+
fn description(&self) -> &str {
353+
"invalid IP address syntax"
354+
}
355+
}

0 commit comments

Comments
 (0)