byteor_transport_shm/
error.rs1use std::path::PathBuf;
4
5#[derive(Debug)]
7pub enum Error {
8 Io(std::io::Error),
10
11 IoAt {
13 op: &'static str,
15 path: PathBuf,
17 source: std::io::Error,
19 },
20
21 Layout(indexbus_core::Error),
23
24 RegionTooSmall {
26 needed: usize,
28 found: usize,
30 },
31
32 Misaligned {
34 align: usize,
36 },
37}
38
39impl core::fmt::Display for Error {
40 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
41 match self {
42 Error::Io(e) => write!(f, "io error: {e}"),
43 Error::IoAt { op, path, source } => {
44 write!(f, "io error ({op}) at '{}': {source}", path.display())
45 }
46 Error::Layout(e) => write!(f, "layout error: {e:?}"),
47 Error::RegionTooSmall { needed, found } => {
48 write!(f, "region too small: needed={needed} found={found}")
49 }
50 Error::Misaligned { align } => write!(f, "misaligned mapping (align={align})"),
51 }
52 }
53}
54
55impl std::error::Error for Error {
56 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
57 match self {
58 Error::Io(e) => Some(e),
59 Error::IoAt { source, .. } => Some(source),
60 _ => None,
61 }
62 }
63}
64
65impl From<std::io::Error> for Error {
66 fn from(value: std::io::Error) -> Self {
67 Self::Io(value)
68 }
69}
70
71impl From<indexbus_core::Error> for Error {
72 fn from(value: indexbus_core::Error) -> Self {
73 Self::Layout(value)
74 }
75}