Implement std::error::Error for Error.
This commit is contained in:
parent
20cfd5200e
commit
43d668e9ef
20
src/lib.rs
20
src/lib.rs
@ -14,6 +14,7 @@ extern crate url;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
|
use std::error::Error as StdError;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::fmt::{Display, Formatter, Result as FmtResult};
|
use std::fmt::{Display, Formatter, Result as FmtResult};
|
||||||
|
|
||||||
@ -198,6 +199,25 @@ fn parse_id<'a>(required_sigil: char, id: &'a str) -> Result<(&'a str, Host, u16
|
|||||||
Ok((localpart, host, port))
|
Ok((localpart, host, port))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for Error {
|
||||||
|
fn fmt(&self, f: &mut Formatter) -> FmtResult {
|
||||||
|
write!(f, "{}", self.description())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StdError for Error {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
match *self {
|
||||||
|
Error::InvalidCharacters => "localpart contains invalid characters",
|
||||||
|
Error::InvalidHost => "server name is not a valid IP address or domain name",
|
||||||
|
Error::MaximumLengthExceeded => "ID exceeds 255 bytes",
|
||||||
|
Error::MinimumLengthNotSatisfied => "ID must be at least 4 characters",
|
||||||
|
Error::MissingDelimiter => "colon is required between localpart and server name",
|
||||||
|
Error::MissingSigil => "leading sigil is missing",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl EventId {
|
impl EventId {
|
||||||
/// Attempts to generate an `EventId` for the given origin server with a localpart consisting
|
/// Attempts to generate an `EventId` for the given origin server with a localpart consisting
|
||||||
/// of 18 random ASCII characters.
|
/// of 18 random ASCII characters.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user