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, Default)]
26pub enum State {
27    #[serde(rename = "succeeded")]
28    #[default]
29    Succeeded,
30    #[serde(rename = "in_progress")]
31    InProgress,
32    #[serde(rename = "pending")]
33    Pending,
34    #[serde(rename = "failed")]
35    Failed,
36}
37
38impl std::fmt::Display for State {
39    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
40        match self {
41            Self::Succeeded => write!(f, "succeeded"),
42            Self::InProgress => write!(f, "in_progress"),
43            Self::Pending => write!(f, "pending"),
44            Self::Failed => write!(f, "failed"),
45        }
46    }
47}