mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Merge branch 'no-failure' into 'master'
Remove failure See merge request xmpp-rs/jid-rs!19
This commit is contained in:
commit
e2f9bdbf1b
2 changed files with 12 additions and 10 deletions
|
@ -19,6 +19,4 @@ edition = "2018"
|
|||
gitlab = { repository = "xmpp-rs/jid-rs" }
|
||||
|
||||
[dependencies]
|
||||
failure = "0.1.1"
|
||||
failure_derive = "0.1.1"
|
||||
minidom = { version = "0.11", optional = true }
|
||||
|
|
20
src/lib.rs
20
src/lib.rs
|
@ -14,34 +14,38 @@
|
|||
//!
|
||||
//! For usage, check the documentation on the `Jid` struct.
|
||||
|
||||
#[macro_use]
|
||||
extern crate failure_derive;
|
||||
|
||||
use std::convert::Into;
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
/// An error that signifies that a `Jid` cannot be parsed from a string.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Fail)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
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 there is no resource, that is string contains no /.
|
||||
#[fail(display = "no resource found in this full JID")]
|
||||
NoResource,
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
||||
impl fmt::Display for JidParseError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{}", match self {
|
||||
JidParseError::NoDomain => "no domain found in this JID",
|
||||
JidParseError::NoResource => "no resource found in this full JID",
|
||||
JidParseError::EmptyNode => "nodepart empty despite the presence of a @",
|
||||
JidParseError::EmptyResource => "resource empty despite the presence of a /",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// An enum representing a Jabber ID. It can be either a `FullJid` or a `BareJid`.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Jid {
|
||||
|
|
Loading…
Reference in a new issue