1use core::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum Error {
6 BadPrefix {
10 expected: String,
12 found: String,
14 },
15 InvalidEncoding,
17 InvalidUuid,
19}
20
21impl fmt::Display for Error {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 Error::BadPrefix { expected, found } => {
25 write!(f, "xuid: bad prefix {found:?}, expected {expected:?}")
26 }
27 Error::InvalidEncoding => write!(f, "xuid: invalid base32 encoding"),
28 Error::InvalidUuid => write!(f, "xuid: invalid uuid"),
29 }
30 }
31}
32
33impl std::error::Error for Error {}
34
35impl From<uuid::Error> for Error {
36 fn from(_: uuid::Error) -> Self {
37 Error::InvalidUuid
38 }
39}
40
41impl From<data_encoding::DecodeError> for Error {
42 fn from(_: data_encoding::DecodeError) -> Self {
43 Error::InvalidEncoding
44 }
45}