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
34impl StringifiedEpochTimeUnitSeconds {
35 pub fn as_str(&self) -> String {
36 match self {
37 StringifiedEpochTimeUnitSeconds::StringValue(s) => s.clone(),
38 StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n) => n.to_string(),
39 }
40 }
41
42 pub fn as_num(&self) -> Option<u64> {
43 match self {
44 StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n) => Some(*n),
45 _ => None,
46 }
47 }
48}
49
50impl From<u64> for StringifiedEpochTimeUnitSeconds {
51 fn from(n: u64) -> Self {
52 StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n)
53 }
54}
55
56impl From<&str> for StringifiedEpochTimeUnitSeconds {
57 fn from(s: &str) -> Self {
58 StringifiedEpochTimeUnitSeconds::StringValue(s.to_string())
59 }
60}
61
62impl From<String> for StringifiedEpochTimeUnitSeconds {
63 fn from(s: String) -> Self {
64 StringifiedEpochTimeUnitSeconds::StringValue(s)
65 }
66}