1 use { 2 failure::{Backtrace, Fail}, 3 netio::bytes_errors::{BytesReadError, BytesWriteError}, 4 std::{fmt, time::SystemTimeError}, 5 }; 6 7 #[derive(Debug, Fail)] 8 pub enum HandshakeErrorValue { 9 #[fail(display = "bytes read error: {}", _0)] 10 BytesReadError(BytesReadError), 11 #[fail(display = "bytes write error: {}", _0)] 12 BytesWriteError(BytesWriteError), 13 #[fail(display = "system time error: {}", _0)] 14 SysTimeError(SystemTimeError), 15 #[fail(display = "Digest not found error")] 16 DigestNotFound, 17 #[fail(display = "s0 version not correct error")] 18 S0VersionNotCorrect, 19 } 20 21 #[derive(Debug)] 22 pub struct HandshakeError { 23 pub value: HandshakeErrorValue, 24 } 25 26 impl From<HandshakeErrorValue> for HandshakeError { 27 fn from(val: HandshakeErrorValue) -> Self { 28 HandshakeError { value: val } 29 } 30 } 31 32 impl From<BytesReadError> for HandshakeError { 33 fn from(error: BytesReadError) -> Self { 34 HandshakeError { 35 value: HandshakeErrorValue::BytesReadError(error), 36 } 37 } 38 } 39 40 impl From<BytesWriteError> for HandshakeError { 41 fn from(error: BytesWriteError) -> Self { 42 HandshakeError { 43 value: HandshakeErrorValue::BytesWriteError(error), 44 } 45 } 46 } 47 48 impl From<SystemTimeError> for HandshakeError { 49 fn from(error: SystemTimeError) -> Self { 50 HandshakeError { 51 value: HandshakeErrorValue::SysTimeError(error), 52 } 53 } 54 } 55 56 impl fmt::Display for HandshakeError { 57 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 58 fmt::Display::fmt(&self.value, f) 59 } 60 } 61 62 impl Fail for HandshakeError { 63 fn cause(&self) -> Option<&dyn Fail> { 64 self.value.cause() 65 } 66 67 fn backtrace(&self) -> Option<&Backtrace> { 68 self.value.backtrace() 69 } 70 } 71