implement Fail on JidParseError

Emmanuel Gil Peyrot created

Change summary

Cargo.toml |  2 ++
src/lib.rs | 10 +++++++++-
2 files changed, 11 insertions(+), 1 deletion(-)

Detailed changes

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 }

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,
 }