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
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}