Skip to main content

opensearch_client/common/
stringified_epoch_time_unit_millis.rs

1/*
2 * opensearch-client
3 *
4 * Rust Client for OpenSearch
5 *
6 * The version of the OpenAPI document: 3.1.0
7 * Contact: alberto.paro@gmail.com
8 * Generated by Paro OpenAPI Generator
9 */
10use serde::{Deserialize, Serialize};
11
12#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13#[serde(untagged)]
14pub enum StringifiedEpochTimeUnitMillis {
15    StringValue(String),
16    EpochTimeUnitMillisValue(u64),
17}
18impl Default for StringifiedEpochTimeUnitMillis {
19    fn default() -> Self {
20        StringifiedEpochTimeUnitMillis::EpochTimeUnitMillisValue(0)
21    }
22}
23
24impl std::fmt::Display for StringifiedEpochTimeUnitMillis {
25    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
26        match self {
27            StringifiedEpochTimeUnitMillis::StringValue(s) => write!(f, "{}", s),
28            StringifiedEpochTimeUnitMillis::EpochTimeUnitMillisValue(n) => write!(f, "{}", n),
29        }
30    }
31}
32
33impl StringifiedEpochTimeUnitMillis {
34    pub fn as_str(&self) -> String {
35        match self {
36            StringifiedEpochTimeUnitMillis::StringValue(s) => s.clone(),
37            StringifiedEpochTimeUnitMillis::EpochTimeUnitMillisValue(n) => n.to_string(),
38        }
39    }
40
41    pub fn as_num(&self) -> Option<u64> {
42        match self {
43            StringifiedEpochTimeUnitMillis::EpochTimeUnitMillisValue(n) => Some(*n),
44            _ => None,
45        }
46    }
47}
48
49impl From<u64> for StringifiedEpochTimeUnitMillis {
50    fn from(n: u64) -> Self {
51        StringifiedEpochTimeUnitMillis::EpochTimeUnitMillisValue(n)
52    }
53}
54
55impl From<&str> for StringifiedEpochTimeUnitMillis {
56    fn from(s: &str) -> Self {
57        StringifiedEpochTimeUnitMillis::StringValue(s.to_string())
58    }
59}
60
61impl From<String> for StringifiedEpochTimeUnitMillis {
62    fn from(s: String) -> Self {
63        StringifiedEpochTimeUnitMillis::StringValue(s)
64    }
65}