1use alloc::string::ToString;
4use core::fmt;
5
6#[derive(Clone, Copy, Eq, PartialEq)]
10pub struct ParseError(phc::Error);
11
12impl ParseError {
13 pub(crate) fn new(err: phc::Error) -> Self {
15 Self(err)
16 }
17}
18
19impl fmt::Debug for ParseError {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 f.debug_tuple("ParseError")
22 .field(&self.0.to_string())
23 .finish()
24 }
25}
26
27impl fmt::Display for ParseError {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 write!(f, "{}", &self.0)
30 }
31}
32
33#[derive(Clone, Copy, Debug, Eq, PartialEq)]
35pub enum VerifyError {
36 Parse(ParseError),
38
39 PasswordInvalid,
41}
42
43impl fmt::Display for VerifyError {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 match self {
46 Self::Parse(err) => write!(f, "{err}"),
47 Self::PasswordInvalid => write!(f, "password is invalid"),
48 }
49 }
50}
51
52impl From<ParseError> for VerifyError {
53 fn from(err: ParseError) -> VerifyError {
54 VerifyError::Parse(err)
55 }
56}
57
58#[cfg(feature = "std")]
59impl std::error::Error for ParseError {}
60
61#[cfg(feature = "std")]
62impl std::error::Error for VerifyError {}