Skip to main content

opensearch_client/common/
stringified_epoch_time_unit_seconds.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/// Certain APIs may return values, including numbers such as epoch timestamps, as strings. This setting captures
13/// this behavior while keeping the semantics of the field type.
14/// 
15/// Depending on the target language, code generators can keep the union or remove it and leniently parse
16/// strings to the target type.
17
18#[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}