implement Fail on JidParseError

This commit is contained in:
Emmanuel Gil Peyrot 2018-03-01 16:25:59 +01:00
parent 87d59181cb
commit fd4a513779
2 changed files with 11 additions and 1 deletions

View file

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

View file

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