error: Add Error::Jid(Box<JidParseError>)

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-10-16 10:57:24 +02:00
parent 4d00060817
commit 43d2697aaa
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -17,7 +17,7 @@ use std::error::Error as StdError;
use std::fmt;
use tokio_xmpp::Error as TokioXMPPError;
use xmpp_parsers::{Error as ParserError, FullJid, Jid};
use xmpp_parsers::{Error as ParserError, FullJid, Jid, JidParseError};
#[derive(Debug)]
pub enum Error {
@ -31,6 +31,8 @@ pub enum Error {
SessionAlreadyExists(FullJid),
/// Raised when fetching an occupant with a nickname that isn't assigned in the room.
ParticipantNotFound(String),
/// Jid Parse errors
Jid(Box<JidParseError>),
/// TokioXMPP errors
Xmpp(Box<TokioXMPPError>),
/// Parser errors
@ -47,12 +49,19 @@ impl fmt::Display for Error {
Error::NonexistantSession(err) => write!(f, "Session doesn't exist: {}", err),
Error::SessionAlreadyExists(err) => write!(f, "Session already exist: {}", err),
Error::ParticipantNotFound(err) => write!(f, "Participant not found: {}", err),
Error::Jid(err) => write!(f, "Jid Parse error: {}", err),
Error::Xmpp(err) => write!(f, "XMPP error: {}", err),
Error::Parser(err) => write!(f, "Parser error: {}", err),
}
}
}
impl From<JidParseError> for Error {
fn from(err: JidParseError) -> Error {
Error::Jid(Box::new(err))
}
}
impl From<TokioXMPPError> for Error {
fn from(err: TokioXMPPError) -> Error {
Error::Xmpp(Box::new(err))