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

use std::fmt;
use std::error::Error;

/// Either the length or the format of a slice is incorrect
#[derive(Debug, Copy, Clone)]
pub struct TryFromError(());

impl TryFromError {
	pub(crate) fn from_any<T>(_: T) -> Self {
		Self(())
	}
}

impl fmt::Display for TryFromError {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		f.write_str(
			"TryFrom<&[u8]> failed: \
			either the length is incorrect or the format"
		)
	}
}

impl Error for TryFromError {}

/// Either the length or the format of a slice is incorrect
#[derive(Debug, Copy, Clone)]
#[non_exhaustive]
pub enum DecodeError {
	InvalidLength,
	InvalidBytes
}

impl DecodeError {
	#[cfg(feature = "b64")]
	pub(crate) fn inv_bytes<T>(_: T) -> Self {
		Self::InvalidBytes
	}
}

impl fmt::Display for DecodeError {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		fmt::Debug::fmt(self, f)
	}
}

impl Error for DecodeError {}