aw_test/models/
execution.rs

1#![allow(unused)]
2use serde::{Deserialize, Serialize, Deserializer};
3use std::collections::HashMap;
4use serde_json::value::Value;
5use std::fmt::Display;
6use super::*;
7
8#[derive(Debug, Serialize, Clone)]
9#[serde(deny_unknown_fields)]
10#[serde(untagged)]
11pub enum EmptyOption<T> {
12    Some(T),
13    None {},
14}
15
16impl<T> Display for EmptyOption<T>
17where
18    T: Display,
19{
20    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21        match self {
22            EmptyOption::Some(t) => write!(f, "{}", t),
23            EmptyOption::None {} => write!(f, ""),
24        }
25    }
26}
27
28impl<'de, T> Deserialize<'de> for EmptyOption<T>
29where
30    T: Deserialize<'de>,
31{
32    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
33    where
34        D: Deserializer<'de>,
35    {
36        Option::deserialize(deserializer).map(Into::into)
37    }
38}
39
40impl<T> From<EmptyOption<T>> for Option<T> {
41    fn from(empty_option: EmptyOption<T>) -> Option<T> {
42        match empty_option {
43            EmptyOption::Some(option) => Some(option),
44            EmptyOption::None {} => None,
45        }
46    }
47}
48
49impl<T> From<Option<T>> for EmptyOption<T> {
50    fn from(option: Option<T>) -> EmptyOption<T> {
51        match option {
52            Some(option) => EmptyOption::Some(option),
53            None {} => EmptyOption::None {},
54        }
55    }
56}
57
58impl<T> EmptyOption<T> {
59    fn into_option(self) -> Option<T> {
60        self.into()
61    }
62    fn as_option(&self) -> Option<&T> {
63        match self {
64            EmptyOption::Some(option) => Some(option),
65            EmptyOption::None {} => None,
66        }
67    }
68}
69
70#[derive(Serialize, Deserialize, Debug, Clone)]
71pub struct Execution {
72        #[serde(rename(serialize = "id", deserialize = "$id"))]
73        pub id: String,
74        #[serde(rename(serialize = "read", deserialize = "$read"))]
75        pub read: Vec<String>,
76        pub functionId: String,
77        pub dateCreated: i64,
78        pub trigger: String,
79        pub status: String,
80        pub statusCode: i64,
81        pub stdout: String,
82        pub stderr: String,
83        pub time: f64,
84}
85
86impl Display for Execution {
87    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88        let mut formatBuffer = String::new();
89        formatBuffer.push_str(&format!("{:?}", self.id));
90        for item in &self.read {
91            formatBuffer.push_str(&format!("{:?}", item));
92        }
93        formatBuffer.push_str(&format!("{:?}", self.functionId));
94        formatBuffer.push_str(&format!("{:?}", self.dateCreated));
95        formatBuffer.push_str(&format!("{:?}", self.trigger));
96        formatBuffer.push_str(&format!("{:?}", self.status));
97        formatBuffer.push_str(&format!("{:?}", self.statusCode));
98        formatBuffer.push_str(&format!("{:?}", self.stdout));
99        formatBuffer.push_str(&format!("{:?}", self.stderr));
100        formatBuffer.push_str(&format!("{:?}", self.time));
101
102        write!(f, "{}", formatBuffer)
103    }
104}
105
106impl Execution {
107    pub fn new(id: String, read: Vec<String>, functionId: String, dateCreated: i64, trigger: String, status: String, statusCode: i64, stdout: String, stderr: String, time: f64, ) -> Self {
108        Self {
109            id: id,
110            read: read,
111            functionId: functionId,
112            dateCreated: dateCreated,
113            trigger: trigger,
114            status: status,
115            statusCode: statusCode,
116            stdout: stdout,
117            stderr: stderr,
118            time: time,
119            }
120    }
121}