opensearch_client/common/
stringified_epoch_time_unit_seconds.rs1use serde::{Deserialize, Serialize};
11
12#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum StringifiedEpochTimeUnitSeconds {
21 StringValue(String),
22 EpochTimeUnitSecondsValue(u64),
23}
24
25impl std::fmt::Display for StringifiedEpochTimeUnitSeconds {
26 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
27 match self {
28 StringifiedEpochTimeUnitSeconds::StringValue(s) => write!(f, "{}", s),
29 StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n) => write!(f, "{}", n),
30 }
31 }
32}
33
34
35impl StringifiedEpochTimeUnitSeconds {
36 pub fn as_str(&self) -> String {
37 match self {
38 StringifiedEpochTimeUnitSeconds::StringValue(s) => s.clone(),
39 StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n) => n.to_string(),
40 }
41 }
42
43 pub fn as_num(&self) -> Option<u64> {
44 match self {
45 StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n) => Some(*n),
46 _ => None,
47 }
48 }
49}
50
51impl From<u64> for StringifiedEpochTimeUnitSeconds {
52 fn from(n: u64) -> Self {
53 StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n)
54 }
55}
56
57impl From<&str> for StringifiedEpochTimeUnitSeconds {
58 fn from(s: &str) -> Self {
59 StringifiedEpochTimeUnitSeconds::StringValue(s.to_string())
60 }
61}
62
63impl From<String> for StringifiedEpochTimeUnitSeconds {
64 fn from(s: String) -> Self {
65 StringifiedEpochTimeUnitSeconds::StringValue(s)
66 }
67}