1use std::error;
2use std::fmt;
3
4pub const CANDID_EMPTY_ARG: &[u8] = &[68, 73, 68, 76, 0, 0];
6
7#[allow(missing_docs)]
9#[repr(i32)]
10#[derive(Debug, Clone, Copy)]
11pub enum RejectionCode {
12 NoError = 0,
13 SysFatal = 1,
14 SysTransient = 2,
15 DestinationInvalid = 3,
16 CanisterReject = 4,
17 CanisterError = 5,
18 Unknown,
19}
20
21impl From<i32> for RejectionCode {
22 fn from(code: i32) -> Self {
23 match code {
24 0 => RejectionCode::NoError,
25 1 => RejectionCode::SysFatal,
26 2 => RejectionCode::SysTransient,
27 3 => RejectionCode::DestinationInvalid,
28 4 => RejectionCode::CanisterReject,
29 5 => RejectionCode::CanisterError,
30 _ => RejectionCode::Unknown,
31 }
32 }
33}
34
35impl From<u32> for RejectionCode {
36 fn from(code: u32) -> Self {
37 RejectionCode::from(code as i32)
38 }
39}
40
41#[derive(Debug)]
42pub enum CallError {
43 CouldNotSend,
45 Rejected(RejectionCode, String),
48 ResponseDeserializationError(Vec<u8>),
52}
53
54impl fmt::Display for CallError {
55 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
56 match self {
57 CallError::CouldNotSend => f.write_str("Could not send message"),
58 CallError::Rejected(c, m) => write!(f, "Call rejected (code={:?}): '{}'", c, m),
59 CallError::ResponseDeserializationError(..) => {
60 f.write_str("Could not deserialize the response.")
61 }
62 }
63 }
64}
65
66impl error::Error for CallError {}
67
68#[derive(Debug, Eq, PartialEq)]
70pub enum StableMemoryError {
71 OutOfMemory,
73 OutOfBounds,
75}
76
77impl fmt::Display for StableMemoryError {
78 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
79 match self {
80 Self::OutOfMemory => f.write_str("Out of memory"),
81 Self::OutOfBounds => f.write_str("Read exceeds allocated memory"),
82 }
83 }
84}
85
86impl error::Error for StableMemoryError {}