1use std::{
2 error::Error,
3 fmt::{self, Debug, Display},
4 io,
5};
6
7#[allow(clippy::exhaustive_structs)]
8#[derive(Debug)]
9pub struct IntoPagesError<T: Debug> {
12 pub err: io::Error,
14 pub from: T,
16}
17
18#[allow(clippy::exhaustive_structs)]
19#[derive(Debug)]
20pub struct JoinError<T: Debug> {
23 pub kind: JoinErrorKind,
25 pub parts: T,
27}
28
29#[allow(clippy::exhaustive_enums)]
30#[derive(Debug)]
31pub enum JoinErrorKind {
33 IO(io::Error),
36 NonContiguous,
39}
40
41impl<T: Debug> Display for IntoPagesError<T> {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 f.write_str("Error converting...\n")?;
44 Debug::fmt(&self.from, f)?;
45 f.write_str("\n... into a Pages object:\n")?;
46 Display::fmt(&self.err, f)
47 }
48}
49
50#[allow(clippy::missing_trait_methods)]
51impl<T: Debug> Error for IntoPagesError<T> {
52 fn source(&self) -> Option<&(dyn Error + 'static)> {
53 Some(&self.err)
54 }
55}
56
57impl<T: Debug> Display for JoinError<T> {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 f.write_str("Error joining...\n")?;
60 Debug::fmt(&self.parts, f)?;
61 f.write_str("\n... ")?;
62 Display::fmt(&self.kind, f)
63 }
64}
65
66#[allow(clippy::missing_trait_methods)]
67impl<T: Debug> Error for JoinError<T> {
68 fn source(&self) -> Option<&(dyn Error + 'static)> {
69 match self.kind {
70 JoinErrorKind::NonContiguous => None,
71 JoinErrorKind::IO(ref e) => Some(e),
72 }
73 }
74}
75
76impl Display for JoinErrorKind {
77 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
78 match *self {
79 Self::NonContiguous => {
80 f.write_str("Provided pages are not contiguous or belong to different allocations")
81 }
82 Self::IO(ref e) => Display::fmt(e, f),
83 }
84 }
85}