Skip to main content

twapi_v2/responses/
processing_info.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
4pub struct ProcessingInfo {
5    #[serde(skip_serializing_if = "Option::is_none")]
6    pub check_after_secs: Option<i64>,
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub progress_percent: Option<i64>,
9    #[serde(skip_serializing_if = "Option::is_none")]
10    pub state: Option<State>,
11    #[serde(flatten)]
12    pub extra: std::collections::HashMap<String, serde_json::Value>,
13}
14
15impl ProcessingInfo {
16    pub fn is_empty_extra(&self) -> bool {
17        let res = self.extra.is_empty();
18        if !res {
19            println!("ProcessingInfo {:?}", self.extra);
20        }
21        res
22    }
23}
24
25#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
26#[derive(Default)]
27pub enum State {
28    #[serde(rename = "succeeded")]
29    #[default]
30    Succeeded,
31    #[serde(rename = "in_progress")]
32    InProgress,
33    #[serde(rename = "pending")]
34    Pending,
35    #[serde(rename = "failed")]
36    Failed,
37}
38
39impl std::fmt::Display for State {
40    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
41        match self {
42            Self::Succeeded => write!(f, "succeeded"),
43            Self::InProgress => write!(f, "in_progress"),
44            Self::Pending => write!(f, "pending"),
45            Self::Failed => write!(f, "failed"),
46        }
47    }
48}
49