1use std::fmt;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub struct ZwError {
12 code: i32,
14}
15
16impl ZwError {
17 #[inline]
19 pub const fn from_code(code: i32) -> Self {
20 Self { code }
21 }
22
23 #[inline]
25 pub const fn code(&self) -> i32 {
26 self.code
27 }
28
29 #[inline]
31 pub const fn is_success(&self) -> bool {
32 self.code == 0
33 }
34
35 #[inline]
37 pub const fn is_user_cancelled(&self) -> bool {
38 self.code != 0
41 }
42}
43
44impl fmt::Display for ZwError {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 match self.code {
47 0 => write!(f, "Success"),
48 -10000 => write!(f, "General error"),
49 -31 => write!(f, "Invalid input"),
50 -32 => write!(f, "Input error"),
51 -33 => write!(f, "Input type error"),
52 _ => write!(f, "ZW3D error code: {}", self.code),
53 }
54 }
55}
56
57impl std::error::Error for ZwError {}
58
59pub type ZwResult<T> = Result<T, ZwError>;
61
62impl ZwError {
64 pub const NO_ERROR: Self = Self { code: 0 };
66
67 pub const GENERAL_ERROR: Self = Self { code: -10000 };
69
70 pub const INVALID_INPUT: Self = Self { code: -31 };
72
73 pub const INPUT_ERROR: Self = Self { code: -32 };
75
76 pub const INPUT_TYPE_ERROR: Self = Self { code: -33 };
78}
79