1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use std::convert::From;
use derive_more::{Display, Error};
use validator::ValidationErrors;
#[derive(Debug, PartialEq, Display, Clone, Error)]
#[cfg(not(tarpaulin_include))]
pub enum CredsError {
#[display(fmt = "the value you passed contains profainity")]
ProfainityError,
#[display(fmt = "username_case_mapped violation")]
UsernameCaseMappedError,
#[display(fmt = "contains blacklisted words")]
BlacklistError,
#[display(fmt = "The value passed in not an email")]
NotAnEmail,
#[display(fmt = "Password too short")]
PasswordTooShort,
#[display(fmt = "Password too long")]
PasswordTooLong,
#[display(fmt = "{}", _0)]
Argon2Error(argon2::Error),
}
impl From<argon2::Error> for CredsError {
fn from(e: argon2::Error) -> CredsError {
CredsError::Argon2Error(e)
}
}
impl From<ValidationErrors> for CredsError {
fn from(_: ValidationErrors) -> CredsError {
CredsError::NotAnEmail
}
}
pub type CredsResult<V> = std::result::Result<V, crate::errors::CredsError>;