rs_password_utils/
errors.rs1use std::{fmt, result};
15use std::num::ParseIntError;
16use std::str::Utf8Error;
17use std::io;
18
19use hex::FromHexError;
20use hyper;
21use hyper::http::uri::InvalidUri;
22
23pub type Result<T> = result::Result<T, PasswordUtilsError>;
24
25#[derive(Debug, PartialEq, Eq, Clone)]
26pub enum PasswordUtilsError {
27 General(String),
28 CommunicationWithThirdPartyApiError(String),
29 ParseError(String),
30}
31
32impl fmt::Display for PasswordUtilsError {
33 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34 match self {
35 &PasswordUtilsError::General(ref message) => write!(f, "{}", message),
36 &PasswordUtilsError::CommunicationWithThirdPartyApiError(ref message) => write!(f, "{}", message),
37 &PasswordUtilsError::ParseError(ref message) => write!(f, "{}", message),
38 }
39 }
40}
41
42impl From<hyper::Error> for PasswordUtilsError {
43 fn from(err: hyper::Error) -> PasswordUtilsError {
44 PasswordUtilsError::CommunicationWithThirdPartyApiError(format!("{:?}", err))
45 }
46}
47
48impl From<InvalidUri> for PasswordUtilsError {
49 fn from(err: InvalidUri) -> PasswordUtilsError {
50 PasswordUtilsError::CommunicationWithThirdPartyApiError(format!("{:?}", err))
51 }
52}
53
54impl From<Utf8Error> for PasswordUtilsError {
55 fn from(err: Utf8Error) -> PasswordUtilsError {
56 PasswordUtilsError::ParseError(format!("{:?}", err))
57 }
58}
59
60impl From<FromHexError> for PasswordUtilsError {
61 fn from(err: FromHexError) -> PasswordUtilsError {
62 PasswordUtilsError::ParseError(format!("{:?}", err))
63 }
64}
65
66impl From<ParseIntError> for PasswordUtilsError {
67 fn from(err: ParseIntError) -> PasswordUtilsError {
68 PasswordUtilsError::ParseError(format!("{:?}", err))
69 }
70}
71
72impl From<io::Error> for PasswordUtilsError {
73 fn from(err: io::Error) -> PasswordUtilsError {
74 PasswordUtilsError::General(format!("{:?}", err))
75 }
76}