2017-04-29 21:14:34 +00:00
|
|
|
// Copyright (c) 2017 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2017-04-18 19:44:36 +00:00
|
|
|
use std::convert::From;
|
|
|
|
use std::io;
|
2017-04-22 16:39:00 +00:00
|
|
|
use std::num;
|
2017-05-06 11:48:42 +00:00
|
|
|
use std::string;
|
2017-06-17 02:36:12 +00:00
|
|
|
use std::fmt;
|
2017-04-18 19:44:36 +00:00
|
|
|
|
2017-04-21 01:46:41 +00:00
|
|
|
use base64;
|
2017-04-18 19:44:36 +00:00
|
|
|
use minidom;
|
2017-04-29 05:06:41 +00:00
|
|
|
use jid;
|
2017-05-27 11:20:19 +00:00
|
|
|
use chrono;
|
2017-04-18 19:44:36 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2017-04-21 01:46:41 +00:00
|
|
|
ParseError(&'static str),
|
2017-04-18 19:44:36 +00:00
|
|
|
IoError(io::Error),
|
|
|
|
XMLError(minidom::Error),
|
2017-04-27 17:33:02 +00:00
|
|
|
Base64Error(base64::DecodeError),
|
2017-04-22 16:39:00 +00:00
|
|
|
ParseIntError(num::ParseIntError),
|
2017-05-06 11:48:42 +00:00
|
|
|
ParseStringError(string::ParseError),
|
2017-04-29 05:06:41 +00:00
|
|
|
JidParseError(jid::JidParseError),
|
2017-05-27 11:20:19 +00:00
|
|
|
ChronoParseError(chrono::ParseError),
|
2017-04-18 19:44:36 +00:00
|
|
|
}
|
|
|
|
|
2017-06-17 02:36:12 +00:00
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
|
|
|
Error::ParseError(s) => write!(fmt, "{}", s),
|
|
|
|
Error::IoError(ref e) => write!(fmt, "{}", e),
|
|
|
|
Error::XMLError(ref e) => write!(fmt, "{}", e),
|
|
|
|
Error::Base64Error(ref e) => write!(fmt, "{}", e),
|
|
|
|
Error::ParseIntError(ref e) => write!(fmt, "{}", e),
|
|
|
|
Error::ParseStringError(ref e) => write!(fmt, "{}", e),
|
|
|
|
Error::JidParseError(_) => write!(fmt, "JID parse error"),
|
|
|
|
Error::ChronoParseError(ref e) => write!(fmt, "{}", e),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-18 19:44:36 +00:00
|
|
|
impl From<io::Error> for Error {
|
|
|
|
fn from(err: io::Error) -> Error {
|
|
|
|
Error::IoError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<minidom::Error> for Error {
|
|
|
|
fn from(err: minidom::Error) -> Error {
|
|
|
|
Error::XMLError(err)
|
|
|
|
}
|
|
|
|
}
|
2017-04-21 01:46:41 +00:00
|
|
|
|
2017-04-27 17:33:02 +00:00
|
|
|
impl From<base64::DecodeError> for Error {
|
|
|
|
fn from(err: base64::DecodeError) -> Error {
|
2017-04-21 01:46:41 +00:00
|
|
|
Error::Base64Error(err)
|
|
|
|
}
|
|
|
|
}
|
2017-04-22 16:39:00 +00:00
|
|
|
|
|
|
|
impl From<num::ParseIntError> for Error {
|
|
|
|
fn from(err: num::ParseIntError) -> Error {
|
|
|
|
Error::ParseIntError(err)
|
|
|
|
}
|
|
|
|
}
|
2017-04-29 05:06:41 +00:00
|
|
|
|
2017-05-06 11:48:42 +00:00
|
|
|
impl From<string::ParseError> for Error {
|
|
|
|
fn from(err: string::ParseError) -> Error {
|
|
|
|
Error::ParseStringError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-29 05:06:41 +00:00
|
|
|
impl From<jid::JidParseError> for Error {
|
|
|
|
fn from(err: jid::JidParseError) -> Error {
|
|
|
|
Error::JidParseError(err)
|
|
|
|
}
|
|
|
|
}
|
2017-05-27 11:20:19 +00:00
|
|
|
|
|
|
|
impl From<chrono::ParseError> for Error {
|
|
|
|
fn from(err: chrono::ParseError) -> Error {
|
|
|
|
Error::ChronoParseError(err)
|
|
|
|
}
|
|
|
|
}
|