1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::result;
pub type Result<T> = result::Result<T, self::Error>;
pub type FunctionResult = Result<i64>;
pub type MultipleFunctionResult = Result<Vec<u8>>;
pub const STATUS_SUCCESS: i64 = 0;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct ExecutionError {
code: i8,
description: Option<String>,
}
impl ExecutionError {
pub fn new(code: i8) -> Self {
Self {
code,
description: None,
}
}
pub fn with_description<T: Into<String>>(code: i8, description: T) -> Self {
Self {
code,
description: Some(description.into()),
}
}
}
impl From<Error> for ExecutionError {
fn from(value: Error) -> ExecutionError {
let description = format!("{}", value);
ExecutionError::with_description(value as i8, description)
}
}
#[repr(i8)]
#[derive(Debug, Fail)]
pub enum Error {
#[fail(display = "Failed serialize the given data structure as a JSON byte ")]
SerializeJson = -1,
#[fail(display = "Failed deserialize the given byte data to structure")]
DeserializeJson = -2,
}