twizzler_rt_abi/
error.rs

1use core::fmt::Display;
2
3use crate::bindings::{self};
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
6#[repr(transparent)]
7pub struct RawTwzError(bindings::twz_error);
8
9impl RawTwzError {
10    pub fn category(&self) -> ErrorCategory {
11        let cat = (self.0 & bindings::ERROR_CATEGORY_MASK) >> bindings::ERROR_CATEGORY_SHIFT;
12        match cat as u16 {
13            bindings::GENERIC_ERROR => ErrorCategory::Generic,
14            bindings::ARGUMENT_ERROR => ErrorCategory::Argument,
15            bindings::RESOURCE_ERROR => ErrorCategory::Resource,
16            bindings::NAMING_ERROR => ErrorCategory::Naming,
17            bindings::OBJECT_ERROR => ErrorCategory::Object,
18            bindings::IO_ERROR => ErrorCategory::Io,
19            bindings::SECURITY_ERROR => ErrorCategory::Security,
20            _ => ErrorCategory::Uncategorized,
21        }
22    }
23
24    pub fn code(&self) -> u16 {
25        ((self.0 & bindings::ERROR_CODE_MASK) >> bindings::ERROR_CODE_SHIFT) as u16
26    }
27
28    pub fn from_parts(cat: u16, code: u16) -> Self {
29        let cat = ((cat as u64) << bindings::ERROR_CATEGORY_SHIFT) & bindings::ERROR_CATEGORY_MASK;
30        let code = ((code as u64) << bindings::ERROR_CODE_SHIFT) & bindings::ERROR_CODE_MASK;
31        Self(cat | code)
32    }
33
34    pub fn error(&self) -> TwzError {
35        match self.category() {
36            ErrorCategory::Uncategorized => TwzError::Uncategorized(self.code()),
37            ErrorCategory::Generic => GenericError::twz_error_from_code(self.code()),
38            ErrorCategory::Argument => ArgumentError::twz_error_from_code(self.code()),
39            ErrorCategory::Resource => ResourceError::twz_error_from_code(self.code()),
40            ErrorCategory::Naming => NamingError::twz_error_from_code(self.code()),
41            ErrorCategory::Object => ObjectError::twz_error_from_code(self.code()),
42            ErrorCategory::Io => IoError::twz_error_from_code(self.code()),
43            ErrorCategory::Security => SecurityError::twz_error_from_code(self.code()),
44        }
45    }
46
47    pub fn new(raw: bindings::twz_error) -> Self {
48        Self(raw)
49    }
50
51    pub fn is_success(&self) -> bool {
52        self.code() == bindings::SUCCESS
53    }
54
55    pub fn raw(&self) -> bindings::twz_error {
56        self.0
57    }
58
59    pub fn success() -> Self {
60        Self(bindings::SUCCESS as u64)
61    }
62
63    pub fn result(&self) -> Result<(), TwzError> {
64        if self.is_success() {
65            Ok(())
66        } else {
67            Err(self.error())
68        }
69    }
70}
71
72impl From<TwzError> for RawTwzError {
73    fn from(value: TwzError) -> Self {
74        RawTwzError(value.raw())
75    }
76}
77
78#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
79pub enum TwzError {
80    Uncategorized(u16),
81    Generic(GenericError),
82    Argument(ArgumentError),
83    Resource(ResourceError),
84    Object(ObjectError),
85    Naming(NamingError),
86    Io(IoError),
87    Security(SecurityError),
88}
89
90impl TwzError {
91    pub const NOT_SUPPORTED: Self = Self::Generic(GenericError::NotSupported);
92    pub const TIMED_OUT: Self = Self::Generic(GenericError::TimedOut);
93    pub const WOULD_BLOCK: Self = Self::Generic(GenericError::WouldBlock);
94    pub const INVALID_ARGUMENT: Self = Self::Argument(ArgumentError::InvalidArgument);
95
96    pub fn category(&self) -> ErrorCategory {
97        match self {
98            TwzError::Uncategorized(_) => ErrorCategory::Uncategorized,
99            TwzError::Generic(_) => ErrorCategory::Generic,
100            TwzError::Argument(_) => ErrorCategory::Argument,
101            TwzError::Resource(_) => ErrorCategory::Resource,
102            TwzError::Object(_) => ErrorCategory::Object,
103            TwzError::Io(_) => ErrorCategory::Io,
104            TwzError::Naming(_) => ErrorCategory::Naming,
105            TwzError::Security(_) => ErrorCategory::Security,
106        }
107    }
108
109    pub fn raw(&self) -> bindings::twz_error {
110        let cat = self.category().raw();
111        let code = self.code();
112        RawTwzError::from_parts(cat, code).raw()
113    }
114
115    pub fn code(&self) -> u16 {
116        match self {
117            TwzError::Uncategorized(code) => *code,
118            TwzError::Generic(generic_error) => generic_error.code(),
119            TwzError::Argument(argument_error) => argument_error.code(),
120            TwzError::Resource(resource_error) => resource_error.code(),
121            TwzError::Object(object_error) => object_error.code(),
122            TwzError::Io(io_error) => io_error.code(),
123            TwzError::Naming(naming_error) => naming_error.code(),
124            TwzError::Security(security_error) => security_error.code(),
125        }
126    }
127}
128
129impl Display for TwzError {
130    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
131        match self {
132            TwzError::Uncategorized(code) => write!(f, "uncategorized error: {}", code),
133            TwzError::Generic(generic_error) => write!(f, "generic error: {}", generic_error),
134            TwzError::Argument(argument_error) => write!(f, "argument error: {}", argument_error),
135            TwzError::Resource(resource_error) => write!(f, "resource error: {}", resource_error),
136            TwzError::Object(object_error) => write!(f, "object error: {}", object_error),
137            TwzError::Io(io_error) => write!(f, "I/O error: {}", io_error),
138            TwzError::Naming(naming_error) => write!(f, "naming error: {}", naming_error),
139            TwzError::Security(security_error) => write!(f, "security error: {}", security_error),
140        }
141    }
142}
143
144impl core::error::Error for TwzError {}
145
146impl Into<u64> for TwzError {
147    fn into(self) -> u64 {
148        self.raw()
149    }
150}
151
152#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
153#[repr(u16)]
154pub enum ErrorCategory {
155    Uncategorized = bindings::UNCATEGORIZED_ERROR,
156    Generic = bindings::GENERIC_ERROR,
157    Argument = bindings::ARGUMENT_ERROR,
158    Resource = bindings::RESOURCE_ERROR,
159    Naming = bindings::NAMING_ERROR,
160    Object = bindings::OBJECT_ERROR,
161    Io = bindings::IO_ERROR,
162    Security = bindings::SECURITY_ERROR,
163}
164
165impl Display for ErrorCategory {
166    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
167        match self {
168            ErrorCategory::Uncategorized => write!(f, "uncategorized"),
169            ErrorCategory::Generic => write!(f, "generic"),
170            ErrorCategory::Argument => write!(f, "argument"),
171            ErrorCategory::Resource => write!(f, "resource"),
172            ErrorCategory::Naming => write!(f, "naming"),
173            ErrorCategory::Object => write!(f, "object"),
174            ErrorCategory::Io => write!(f, "I/O"),
175            ErrorCategory::Security => write!(f, "security"),
176        }
177    }
178}
179
180impl core::error::Error for ErrorCategory {}
181
182impl ErrorCategory {
183    pub fn raw(&self) -> u16 {
184        *self as u16
185    }
186}
187
188#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
189#[repr(u16)]
190pub enum GenericError {
191    Other = bindings::OTHER_ERROR,
192    NotSupported = bindings::NOT_SUPPORTED,
193    Internal = bindings::INTERNAL,
194    WouldBlock = bindings::WOULD_BLOCK,
195    TimedOut = bindings::TIMED_OUT,
196    AccessDenied = bindings::ACCESS_DENIED,
197    NoSuchOperation = bindings::NO_SUCH_OPERATION,
198    Interrupted = bindings::INTERRUPTED,
199    InProgress = bindings::IN_PROGRESS,
200}
201
202impl GenericError {
203    fn twz_error_from_code(code: u16) -> TwzError {
204        match code {
205            bindings::NOT_SUPPORTED => TwzError::Generic(GenericError::NotSupported),
206            bindings::INTERNAL => TwzError::Generic(GenericError::Internal),
207            bindings::WOULD_BLOCK => TwzError::Generic(GenericError::WouldBlock),
208            bindings::TIMED_OUT => TwzError::Generic(GenericError::TimedOut),
209            bindings::NO_SUCH_OPERATION => TwzError::Generic(GenericError::NoSuchOperation),
210            _ => TwzError::Uncategorized(code),
211        }
212    }
213
214    fn code(&self) -> u16 {
215        *self as u16
216    }
217}
218
219impl Display for GenericError {
220    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
221        match self {
222            GenericError::NotSupported => write!(f, "not supported"),
223            GenericError::Internal => write!(f, "internal"),
224            GenericError::WouldBlock => write!(f, "would block"),
225            GenericError::TimedOut => write!(f, "timed out"),
226            GenericError::AccessDenied => write!(f, "access denied"),
227            GenericError::NoSuchOperation => write!(f, "no such operation"),
228            GenericError::Interrupted => write!(f, "interrupted"),
229            GenericError::InProgress => write!(f, "in-progress"),
230            GenericError::Other => write!(f, "other"),
231        }
232    }
233}
234
235impl core::error::Error for GenericError {}
236
237impl From<GenericError> for TwzError {
238    fn from(value: GenericError) -> Self {
239        Self::Generic(value)
240    }
241}
242
243#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
244#[repr(u16)]
245pub enum ArgumentError {
246    InvalidArgument = bindings::INVALID_ARGUMENT,
247    WrongType = bindings::WRONG_TYPE,
248    InvalidAddress = bindings::INVALID_ADDRESS,
249    BadHandle = bindings::BAD_HANDLE,
250}
251
252impl ArgumentError {
253    fn twz_error_from_code(code: u16) -> TwzError {
254        match code {
255            bindings::INVALID_ARGUMENT => TwzError::Argument(ArgumentError::InvalidArgument),
256            bindings::WRONG_TYPE => TwzError::Argument(ArgumentError::WrongType),
257            bindings::INVALID_ADDRESS => TwzError::Argument(ArgumentError::InvalidAddress),
258            bindings::BAD_HANDLE => TwzError::Argument(ArgumentError::BadHandle),
259            _ => TwzError::Uncategorized(code),
260        }
261    }
262
263    fn code(&self) -> u16 {
264        *self as u16
265    }
266}
267
268impl Display for ArgumentError {
269    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
270        match self {
271            ArgumentError::InvalidArgument => write!(f, "invalid argument"),
272            ArgumentError::WrongType => write!(f, "wrong type"),
273            ArgumentError::InvalidAddress => write!(f, "invalid address"),
274            ArgumentError::BadHandle => write!(f, "bad handle"),
275        }
276    }
277}
278
279impl core::error::Error for ArgumentError {}
280
281impl From<ArgumentError> for TwzError {
282    fn from(value: ArgumentError) -> Self {
283        Self::Argument(value)
284    }
285}
286
287#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
288#[repr(u16)]
289pub enum ResourceError {
290    OutOfMemory = bindings::OUT_OF_MEMORY,
291    OutOfResources = bindings::OUT_OF_RESOURCES,
292    OutOfNames = bindings::OUT_OF_NAMES,
293    Unavailable = bindings::UNAVAILABLE,
294    Refused = bindings::REFUSED,
295    Busy = bindings::BUSY,
296    NotConnected = bindings::NOT_CONNECTED,
297    Unreachable = bindings::UNREACHABLE,
298    NonAtomic = bindings::NON_ATOMIC,
299}
300
301impl ResourceError {
302    fn twz_error_from_code(code: u16) -> TwzError {
303        match code {
304            bindings::OUT_OF_MEMORY => TwzError::Resource(ResourceError::OutOfMemory),
305            bindings::OUT_OF_RESOURCES => TwzError::Resource(ResourceError::OutOfResources),
306            bindings::OUT_OF_NAMES => TwzError::Resource(ResourceError::OutOfNames),
307            bindings::UNAVAILABLE => TwzError::Resource(ResourceError::Unavailable),
308            _ => TwzError::Uncategorized(code),
309        }
310    }
311
312    fn code(&self) -> u16 {
313        *self as u16
314    }
315}
316
317impl Display for ResourceError {
318    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
319        match self {
320            ResourceError::OutOfMemory => write!(f, "out of memory"),
321            ResourceError::OutOfResources => write!(f, "out of resources"),
322            ResourceError::OutOfNames => write!(f, "out of names"),
323            ResourceError::Unavailable => write!(f, "unavailable"),
324            ResourceError::Refused => write!(f, "refused"),
325            ResourceError::Busy => write!(f, "busy"),
326            ResourceError::NotConnected => write!(f, "not connected"),
327            ResourceError::Unreachable => write!(f, "unreachable"),
328            ResourceError::NonAtomic => write!(f, "non-atomic"),
329        }
330    }
331}
332
333impl core::error::Error for ResourceError {}
334
335impl From<ResourceError> for TwzError {
336    fn from(value: ResourceError) -> Self {
337        Self::Resource(value)
338    }
339}
340
341#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
342#[repr(u16)]
343pub enum ObjectError {
344    MapFailed = bindings::MAPPING_FAILED,
345    NotMapped = bindings::NOT_MAPPED,
346    InvalidFote = bindings::INVALID_FOTE,
347    InvalidPtr = bindings::INVALID_PTR,
348    InvalidMeta = bindings::INVALID_META,
349    BaseTypeMismatch = bindings::BASETYPE_MISMATCH,
350    NoSuchObject = bindings::NO_SUCH_OBJECT,
351}
352
353impl ObjectError {
354    fn twz_error_from_code(code: u16) -> TwzError {
355        match code {
356            bindings::MAPPING_FAILED => TwzError::Object(ObjectError::MapFailed),
357            bindings::NOT_MAPPED => TwzError::Object(ObjectError::NotMapped),
358            bindings::INVALID_FOTE => TwzError::Object(ObjectError::InvalidFote),
359            bindings::INVALID_PTR => TwzError::Object(ObjectError::InvalidPtr),
360            bindings::INVALID_META => TwzError::Object(ObjectError::InvalidMeta),
361            bindings::BASETYPE_MISMATCH => TwzError::Object(ObjectError::BaseTypeMismatch),
362            bindings::NO_SUCH_OBJECT => TwzError::Object(ObjectError::NoSuchObject),
363            _ => TwzError::Uncategorized(code),
364        }
365    }
366
367    fn code(&self) -> u16 {
368        *self as u16
369    }
370}
371
372impl Display for ObjectError {
373    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
374        match self {
375            ObjectError::MapFailed => write!(f, "mapping failed"),
376            ObjectError::NotMapped => write!(f, "not mapped"),
377            ObjectError::InvalidFote => write!(f, "invalid FOT entry"),
378            ObjectError::InvalidPtr => write!(f, "invalid pointer"),
379            ObjectError::InvalidMeta => write!(f, "invalid metadata"),
380            ObjectError::BaseTypeMismatch => write!(f, "base type mismatch"),
381            ObjectError::NoSuchObject => write!(f, "no such object"),
382        }
383    }
384}
385
386impl core::error::Error for ObjectError {}
387
388impl From<ObjectError> for TwzError {
389    fn from(value: ObjectError) -> Self {
390        Self::Object(value)
391    }
392}
393
394#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
395#[repr(u16)]
396pub enum IoError {
397    Other = bindings::OTHER_IO_ERROR,
398    DataLoss = bindings::DATA_LOSS,
399    DeviceError = bindings::DEVICE_ERROR,
400    SeekFailed = bindings::SEEK_FAILED,
401    Reset = bindings::RESET,
402}
403
404impl IoError {
405    fn twz_error_from_code(code: u16) -> TwzError {
406        match code {
407            bindings::OTHER_IO_ERROR => TwzError::Io(IoError::Other),
408            bindings::DATA_LOSS => TwzError::Io(IoError::DataLoss),
409            bindings::DEVICE_ERROR => TwzError::Io(IoError::DeviceError),
410            bindings::SEEK_FAILED => TwzError::Io(IoError::SeekFailed),
411            _ => TwzError::Uncategorized(code),
412        }
413    }
414
415    fn code(&self) -> u16 {
416        *self as u16
417    }
418}
419
420impl Display for IoError {
421    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
422        match self {
423            IoError::Other => write!(f, "other I/O error"),
424            IoError::DataLoss => write!(f, "data loss"),
425            IoError::DeviceError => write!(f, "device error"),
426            IoError::SeekFailed => write!(f, "seek failed"),
427            IoError::Reset => write!(f, "reset"),
428        }
429    }
430}
431
432impl core::error::Error for IoError {}
433
434impl From<IoError> for TwzError {
435    fn from(value: IoError) -> Self {
436        Self::Io(value)
437    }
438}
439
440#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
441#[repr(u16)]
442pub enum NamingError {
443    NotFound = bindings::NOT_FOUND,
444    AlreadyExists = bindings::ALREADY_EXISTS,
445    WrongNameKind = bindings::WRONG_NAME_KIND,
446    AlreadyBound = bindings::ALREADY_BOUND,
447    LinkLoop = bindings::LINK_LOOP,
448    NotEmpty = bindings::NOT_EMPTY,
449}
450
451impl NamingError {
452    fn twz_error_from_code(code: u16) -> TwzError {
453        match code {
454            bindings::NOT_FOUND => TwzError::Naming(NamingError::NotFound),
455            bindings::ALREADY_EXISTS => TwzError::Naming(NamingError::AlreadyExists),
456            bindings::WRONG_NAME_KIND => TwzError::Naming(NamingError::WrongNameKind),
457            bindings::ALREADY_BOUND => TwzError::Naming(NamingError::AlreadyBound),
458            bindings::LINK_LOOP => TwzError::Naming(NamingError::LinkLoop),
459            bindings::NOT_EMPTY => TwzError::Naming(NamingError::NotEmpty),
460            _ => TwzError::Uncategorized(code),
461        }
462    }
463
464    fn code(&self) -> u16 {
465        *self as u16
466    }
467}
468
469impl Display for NamingError {
470    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
471        match self {
472            NamingError::NotFound => write!(f, "not found"),
473            NamingError::AlreadyExists => write!(f, "already exists"),
474            NamingError::WrongNameKind => write!(f, "wrong name kind"),
475            NamingError::AlreadyBound => write!(f, "already bound"),
476            NamingError::LinkLoop => write!(f, "link loop"),
477            NamingError::NotEmpty => write!(f, "not empty"),
478        }
479    }
480}
481
482impl core::error::Error for NamingError {}
483
484impl From<NamingError> for TwzError {
485    fn from(value: NamingError) -> Self {
486        Self::Naming(value)
487    }
488}
489
490#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
491#[repr(u16)]
492pub enum SecurityError {
493    InvalidKey = bindings::INVALID_KEY,
494    InvalidScheme = bindings::INVALID_SCHEME,
495    SignatureMismatch = bindings::SIGNATURE_MISMATCH,
496    GateDenied = bindings::GATE_DENIED,
497    InvalidGate = bindings::INVALID_GATE,
498}
499
500impl SecurityError {
501    fn twz_error_from_code(code: u16) -> TwzError {
502        match code {
503            bindings::INVALID_KEY => TwzError::Security(SecurityError::InvalidKey),
504            bindings::INVALID_SCHEME => TwzError::Security(SecurityError::InvalidScheme),
505            bindings::INVALID_GATE => TwzError::Security(SecurityError::InvalidGate),
506            bindings::GATE_DENIED => TwzError::Security(SecurityError::GateDenied),
507            bindings::SIGNATURE_MISMATCH => TwzError::Security(SecurityError::SignatureMismatch),
508            _ => TwzError::Uncategorized(code),
509        }
510    }
511
512    fn code(&self) -> u16 {
513        *self as u16
514    }
515}
516
517impl Display for SecurityError {
518    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
519        match self {
520            SecurityError::InvalidKey => write!(f, "invalid key"),
521            SecurityError::InvalidScheme => write!(f, "invalid scheme"),
522            SecurityError::SignatureMismatch => write!(f, "signature mismatch"),
523            SecurityError::GateDenied => write!(f, "gate denied"),
524            SecurityError::InvalidGate => write!(f, "invalid gate"),
525        }
526    }
527}
528
529impl core::error::Error for SecurityError {}
530
531impl From<SecurityError> for TwzError {
532    fn from(value: SecurityError) -> Self {
533        Self::Security(value)
534    }
535}
536
537impl From<core::alloc::AllocError> for TwzError {
538    fn from(_value: core::alloc::AllocError) -> Self {
539        ResourceError::OutOfMemory.into()
540    }
541}
542
543#[cfg(all(feature = "stderr", not(doc), not(feature = "rustc-dep-of-std")))]
544extern crate std;
545#[cfg(all(feature = "stderr", not(doc), not(feature = "rustc-dep-of-std")))]
546impl From<std::io::ErrorKind> for TwzError {
547    fn from(value: std::io::ErrorKind) -> Self {
548        match value {
549            std::io::ErrorKind::NotFound => NamingError::NotFound.into(),
550            std::io::ErrorKind::PermissionDenied => GenericError::AccessDenied.into(),
551            std::io::ErrorKind::ConnectionRefused => ResourceError::Refused.into(),
552            std::io::ErrorKind::ConnectionReset => IoError::Reset.into(),
553            std::io::ErrorKind::HostUnreachable => ResourceError::Unreachable.into(),
554            std::io::ErrorKind::NetworkUnreachable => ResourceError::Unreachable.into(),
555            std::io::ErrorKind::ConnectionAborted => IoError::Reset.into(),
556            std::io::ErrorKind::NotConnected => ResourceError::NotConnected.into(),
557            std::io::ErrorKind::AddrInUse => NamingError::AlreadyBound.into(),
558            std::io::ErrorKind::AddrNotAvailable => NamingError::NotFound.into(),
559            std::io::ErrorKind::NetworkDown => ResourceError::Unavailable.into(),
560            std::io::ErrorKind::BrokenPipe => IoError::Reset.into(),
561            std::io::ErrorKind::AlreadyExists => NamingError::AlreadyExists.into(),
562            std::io::ErrorKind::WouldBlock => GenericError::WouldBlock.into(),
563            std::io::ErrorKind::NotADirectory => NamingError::WrongNameKind.into(),
564            std::io::ErrorKind::IsADirectory => NamingError::WrongNameKind.into(),
565            std::io::ErrorKind::DirectoryNotEmpty => NamingError::NotEmpty.into(),
566            std::io::ErrorKind::ReadOnlyFilesystem => ResourceError::Refused.into(),
567            std::io::ErrorKind::FilesystemLoop => NamingError::LinkLoop.into(),
568            std::io::ErrorKind::StaleNetworkFileHandle => ArgumentError::BadHandle.into(),
569            std::io::ErrorKind::InvalidInput => ArgumentError::InvalidArgument.into(),
570            std::io::ErrorKind::InvalidData => GenericError::Internal.into(),
571            std::io::ErrorKind::TimedOut => GenericError::TimedOut.into(),
572            std::io::ErrorKind::WriteZero => IoError::DataLoss.into(),
573            std::io::ErrorKind::StorageFull => ResourceError::OutOfResources.into(),
574            std::io::ErrorKind::NotSeekable => IoError::SeekFailed.into(),
575            std::io::ErrorKind::QuotaExceeded => ResourceError::OutOfResources.into(),
576            std::io::ErrorKind::FileTooLarge => ResourceError::OutOfResources.into(),
577            std::io::ErrorKind::ResourceBusy => ResourceError::Busy.into(),
578            std::io::ErrorKind::ExecutableFileBusy => ResourceError::Busy.into(),
579            std::io::ErrorKind::Deadlock => ResourceError::Busy.into(),
580            std::io::ErrorKind::CrossesDevices => ArgumentError::InvalidArgument.into(),
581            std::io::ErrorKind::TooManyLinks => NamingError::LinkLoop.into(),
582            std::io::ErrorKind::InvalidFilename => ArgumentError::InvalidArgument.into(),
583            std::io::ErrorKind::ArgumentListTooLong => ArgumentError::InvalidArgument.into(),
584            std::io::ErrorKind::Interrupted => GenericError::Interrupted.into(),
585            std::io::ErrorKind::Unsupported => GenericError::NotSupported.into(),
586            std::io::ErrorKind::UnexpectedEof => IoError::Reset.into(),
587            std::io::ErrorKind::OutOfMemory => ResourceError::OutOfMemory.into(),
588            std::io::ErrorKind::InProgress => GenericError::InProgress.into(),
589            _ => GenericError::Other.into(),
590        }
591    }
592}
593
594#[cfg(all(feature = "stderr", not(doc), not(feature = "rustc-dep-of-std")))]
595impl From<std::io::Error> for TwzError {
596    fn from(value: std::io::Error) -> Self {
597        value.kind().into()
598    }
599}
600
601#[cfg(all(feature = "stderr", not(doc), not(feature = "rustc-dep-of-std")))]
602impl From<TwzError> for std::io::Error {
603    fn from(value: TwzError) -> Self {
604        std::io::Error::new(std::io::ErrorKind::Other, value)
605    }
606}