diff --git a/Cargo.toml b/Cargo.toml index cc9916d4eef4a1266f51b3344b3a6735be75a227..e9fcb30c59c8d30160a09348a1b8b6acd8b28510 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,6 @@ license = "LGPL-3.0+" gitlab = { repository = "xmpp-rs/jid-rs" } [dependencies] +failure = "0.1.1" +failure_derive = "0.1.1" minidom = { version = "0.8.0", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 6f2641e21ccd831e19c85472b60c1c10ccb9cafb..fb04453f54df2aec939dcc65985e5de3b5e60c07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,9 @@ //! //! For usage, check the documentation on the `Jid` struct. +extern crate failure; +#[macro_use] extern crate failure_derive; + use std::fmt; use std::convert::Into; @@ -11,14 +14,19 @@ use std::convert::Into; use std::str::FromStr; /// An error that signifies that a `Jid` cannot be parsed from a string. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Fail)] pub enum JidParseError { /// Happens when there is no domain, that is either the string is empty, /// starts with a /, or contains the @/ sequence. + #[fail(display = "no domain found in this JID")] NoDomain, + /// Happens when the node is empty, that is the string starts with a @. + #[fail(display = "nodepart empty despite the presence of a @")] EmptyNode, + /// Happens when the resource is empty, that is the string ends with a /. + #[fail(display = "resource empty despite the presence of a /")] EmptyResource, }