From fd4a51377942cf5020d0bcb7290ce4c4af73dbef Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 1 Mar 2018 16:25:59 +0100 Subject: [PATCH] implement Fail on JidParseError --- Cargo.toml | 2 ++ src/lib.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cc9916d4..e9fcb30c 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 6f2641e2..fb04453f 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, }