implement Fail on JidParseError
This commit is contained in:
parent
87d59181cb
commit
fd4a513779
2 changed files with 11 additions and 1 deletions
|
@ -18,4 +18,6 @@ license = "LGPL-3.0+"
|
||||||
gitlab = { repository = "xmpp-rs/jid-rs" }
|
gitlab = { repository = "xmpp-rs/jid-rs" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
failure = "0.1.1"
|
||||||
|
failure_derive = "0.1.1"
|
||||||
minidom = { version = "0.8.0", optional = true }
|
minidom = { version = "0.8.0", optional = true }
|
||||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -4,6 +4,9 @@
|
||||||
//!
|
//!
|
||||||
//! For usage, check the documentation on the `Jid` struct.
|
//! For usage, check the documentation on the `Jid` struct.
|
||||||
|
|
||||||
|
extern crate failure;
|
||||||
|
#[macro_use] extern crate failure_derive;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use std::convert::Into;
|
use std::convert::Into;
|
||||||
|
@ -11,14 +14,19 @@ use std::convert::Into;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
/// An error that signifies that a `Jid` cannot be parsed from a string.
|
/// 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 {
|
pub enum JidParseError {
|
||||||
/// Happens when there is no domain, that is either the string is empty,
|
/// Happens when there is no domain, that is either the string is empty,
|
||||||
/// starts with a /, or contains the @/ sequence.
|
/// starts with a /, or contains the @/ sequence.
|
||||||
|
#[fail(display = "no domain found in this JID")]
|
||||||
NoDomain,
|
NoDomain,
|
||||||
|
|
||||||
/// Happens when the node is empty, that is the string starts with a @.
|
/// Happens when the node is empty, that is the string starts with a @.
|
||||||
|
#[fail(display = "nodepart empty despite the presence of a @")]
|
||||||
EmptyNode,
|
EmptyNode,
|
||||||
|
|
||||||
/// Happens when the resource is empty, that is the string ends with a /.
|
/// Happens when the resource is empty, that is the string ends with a /.
|
||||||
|
#[fail(display = "resource empty despite the presence of a /")]
|
||||||
EmptyResource,
|
EmptyResource,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue