From f83e9fd9281d4c6613c4a453b194f6f30696b6da Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 7 Sep 2019 16:15:44 +0200 Subject: [PATCH] error: implement std::error::Error. --- src/util/error.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/util/error.rs b/src/util/error.rs index 408c649..b103711 100644 --- a/src/util/error.rs +++ b/src/util/error.rs @@ -8,6 +8,7 @@ use base64; use chrono; use jid; use std::convert::From; +use std::error::Error as StdError; use std::fmt; use std::net; use std::num; @@ -46,6 +47,20 @@ pub enum Error { ChronoParseError(chrono::ParseError), } +impl StdError for Error { + fn cause(&self) -> Option<&dyn StdError> { + match self { + Error::ParseError(_) => None, + Error::Base64Error(e) => Some(e), + Error::ParseIntError(e) => Some(e), + Error::ParseStringError(e) => Some(e), + Error::ParseAddrError(e) => Some(e), + Error::JidParseError(e) => Some(e), + Error::ChronoParseError(e) => Some(e), + } + } +} + impl fmt::Display for Error { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match self {