1use std::{error, fmt};
7
8use crate::platform_impl;
9
10#[non_exhaustive]
12#[derive(Debug)]
13pub enum ExternalError {
14 NotSupported(NotSupportedError),
16 Os(OsError),
18}
19
20#[derive(Clone)]
22pub struct NotSupportedError {
23 _marker: (),
24}
25
26#[derive(Debug)]
28pub struct OsError {
29 line: u32,
30 file: &'static str,
31 error: platform_impl::OsError,
32}
33
34impl NotSupportedError {
35 #[inline]
36 #[allow(dead_code)]
37 pub(crate) fn new() -> NotSupportedError {
38 NotSupportedError { _marker: () }
39 }
40}
41
42impl OsError {
43 #[allow(dead_code)]
44 pub(crate) fn new(line: u32, file: &'static str, error: platform_impl::OsError) -> OsError {
45 OsError { line, file, error }
46 }
47}
48
49#[allow(unused_macros)]
50macro_rules! os_error {
51 ($error:expr) => {{
52 crate::error::OsError::new(line!(), file!(), $error)
53 }};
54}
55
56impl fmt::Display for OsError {
57 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
58 f.pad(&format!(
59 "os error at {}:{}: {}",
60 self.file, self.line, self.error
61 ))
62 }
63}
64
65impl fmt::Display for ExternalError {
66 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
67 match self {
68 ExternalError::NotSupported(e) => e.fmt(f),
69 ExternalError::Os(e) => e.fmt(f),
70 }
71 }
72}
73
74impl fmt::Debug for NotSupportedError {
75 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
76 f.debug_struct("NotSupportedError").finish()
77 }
78}
79
80impl fmt::Display for NotSupportedError {
81 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
82 f.pad("the requested operation is not supported by Tao")
83 }
84}
85
86impl error::Error for OsError {}
87impl error::Error for ExternalError {}
88impl error::Error for NotSupportedError {}