display/
error.rs

1use std::io;
2
3use thiserror::Error;
4
5/// A display error.
6#[derive(Error, Debug)]
7#[non_exhaustive]
8pub enum DisplayError {
9	/// An unexpected error occurred.
10	#[error("Unexpected error")]
11	Unexpected(io::Error),
12}
13
14impl PartialEq for DisplayError {
15	#[inline]
16	#[allow(clippy::pattern_type_mismatch)]
17	fn eq(&self, other: &Self) -> bool {
18		match (self, other) {
19			(Self::Unexpected(self_io_error), Self::Unexpected(other_io_error)) => {
20				self_io_error.kind() == other_io_error.kind()
21			},
22		}
23	}
24}
25
26#[cfg(test)]
27mod test {
28	use super::*;
29
30	#[test]
31	fn partial_eq_io_error_same() {
32		assert_eq!(
33			DisplayError::Unexpected(io::Error::from(io::ErrorKind::Other)),
34			DisplayError::Unexpected(io::Error::from(io::ErrorKind::Other))
35		);
36	}
37
38	#[test]
39	fn partial_eq_io_error_different() {
40		assert_ne!(
41			DisplayError::Unexpected(io::Error::from(io::ErrorKind::Other)),
42			DisplayError::Unexpected(io::Error::from(io::ErrorKind::NotFound))
43		);
44	}
45}