rs_password_utils/
errors.rs1use std::io;
15use std::num::ParseIntError;
16use std::str::Utf8Error;
17use std::{fmt, result};
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) => {
37 write!(f, "{}", message)
38 }
39 &PasswordUtilsError::ParseError(ref message) => write!(f, "{}", message),
40 }
41 }
42}
43
44impl From<hyper::Error> for PasswordUtilsError {
45 fn from(err: hyper::Error) -> PasswordUtilsError {
46 PasswordUtilsError::CommunicationWithThirdPartyApiError(format!("{:?}", err))
47 }
48}
49
50impl From<InvalidUri> for PasswordUtilsError {
51 fn from(err: InvalidUri) -> PasswordUtilsError {
52 PasswordUtilsError::CommunicationWithThirdPartyApiError(format!("{:?}", err))
53 }
54}
55
56impl From<Utf8Error> for PasswordUtilsError {
57 fn from(err: Utf8Error) -> PasswordUtilsError {
58 PasswordUtilsError::ParseError(format!("{:?}", err))
59 }
60}
61
62impl From<FromHexError> for PasswordUtilsError {
63 fn from(err: FromHexError) -> PasswordUtilsError {
64 PasswordUtilsError::ParseError(format!("{:?}", err))
65 }
66}
67
68impl From<ParseIntError> for PasswordUtilsError {
69 fn from(err: ParseIntError) -> PasswordUtilsError {
70 PasswordUtilsError::ParseError(format!("{:?}", err))
71 }
72}
73
74impl From<io::Error> for PasswordUtilsError {
75 fn from(err: io::Error) -> PasswordUtilsError {
76 PasswordUtilsError::General(format!("{:?}", err))
77 }
78}