Skip to main content

gistyr_lib/
lib.rs

1//! ------ !//
2//! gistyr-lib
3//! ------ !//
4
5use std::fmt;
6
7pub const SUCCESS_CODE_U64: u64 = 0;
8pub const SUCCESS_CODE_U32: u32 = 0;
9pub const SUCCESS_CODE_U16: u16 = 0;
10pub const SUCCESS_CODE_U8: u8 = 0;
11
12pub const ERROR_CODE_U64: u64 = 1;
13pub const ERROR_CODE_U32: u32 = 1;
14pub const ERROR_CODE_U16: u16 = 1;
15pub const ERROR_CODE_U8: u8 = 1;
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum Int {
19    U8(u8),
20    U16(u16),
21    U32(u32),
22    U64(u64),
23}
24impl fmt::Display for Int {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        match self {
27            Self::U8(v)  => write!(f, "{}", v),
28            Self::U16(v) => write!(f, "{}", v),
29            Self::U32(v) => write!(f, "{}", v),
30            Self::U64(v) => write!(f, "{}", v),
31        }
32    }
33}
34
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36pub enum OpCode {
37    Null,
38    Authenticated,
39    NotAuthenticated,
40    Continue,
41    Finished,
42    Early,
43    Deinitialized,
44    OneInt(Int),
45    TwoInts(Int, Int),
46    ThreeInts(Int, Int, Int),
47    FourInts(Int, Int, Int, Int),
48}
49impl fmt::Display for OpCode {
50    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51        match self {
52            Self::Null => write!(f, "Null"),
53            Self::Authenticated => write!(f, "Authenticated"),
54            Self::NotAuthenticated => write!(f, "NotAuthenticated"),
55            Self::Continue => write!(f, "Continue"),
56            Self::Finished => write!(f, "Finished"),
57            Self::Early => write!(f, "Early"),
58            Self::Deinitialized => write!(f, "Deinitialized"),
59            Self::OneInt(a) => write!(f, "OneInt({})", a),
60            Self::TwoInts(a, b) => write!(f, "TwoInts({}, {})", a, b),
61            Self::ThreeInts(a, b, c) => write!(f, "ThreeInts({}, {}, {})", a, b, c),
62            Self::FourInts(a, b, c, d) => write!(f, "FourInts({}, {}, {}, {})", a, b, c, d),
63        }
64    }
65}
66
67#[derive(Debug, Clone, PartialEq)]
68pub enum Gistyr {
69    Success(OpCode),
70    Error(String, String, String),
71}
72impl fmt::Display for Gistyr {
73    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74        match self {
75            Self::Success(op) => write!(f, "Success({})", op),
76            Self::Error(lib, func, msg) => write!(f, "Error({}, {}, {})", lib, func, msg),
77        }
78    }
79}
80impl Gistyr {
81    pub fn error<L: Into<String>, F: Into<String>, M: Into<String>>(lib: L, func: F, msg: M) -> Self {
82        return Self::Error(lib.into(), func.into(), msg.into());
83    }
84}
85
86// -------- //
87// end of file
88// -------- //