opensearch-client 0.3.1

Strongly typed OpenSearch Client
Documentation
/*
 * opensearch-client
 *
 * Rust Client for OpenSearch
 *
 * The version of the OpenAPI document: 3.1.0
 * Contact: alberto.paro@gmail.com
 * Generated by Paro OpenAPI Generator
 */
use serde::{Deserialize, Serialize};

/// Certain APIs may return values, including numbers such as epoch timestamps, as strings. This setting captures
/// this behavior while keeping the semantics of the field type.
/// 
/// Depending on the target language, code generators can keep the union or remove it and leniently parse
/// strings to the target type.

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum StringifiedEpochTimeUnitSeconds {
    StringValue(String),
    EpochTimeUnitSecondsValue(u64),
}

impl std::fmt::Display for StringifiedEpochTimeUnitSeconds {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            StringifiedEpochTimeUnitSeconds::StringValue(s) => write!(f, "{}", s),
            StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n) => write!(f, "{}", n),
        }
    }
}


impl StringifiedEpochTimeUnitSeconds {
    pub fn as_str(&self) -> String {
        match self {
            StringifiedEpochTimeUnitSeconds::StringValue(s) => s.clone(),
            StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n) => n.to_string(),
        }
    }

    pub fn as_num(&self) -> Option<u64> {
        match self {
            StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n) => Some(*n),
            _ => None,
        }
    }
}

impl From<u64> for StringifiedEpochTimeUnitSeconds {
    fn from(n: u64) -> Self {
        StringifiedEpochTimeUnitSeconds::EpochTimeUnitSecondsValue(n)
    }
}

impl From<&str> for StringifiedEpochTimeUnitSeconds {
    fn from(s: &str) -> Self {
        StringifiedEpochTimeUnitSeconds::StringValue(s.to_string())
    }
}

impl From<String> for StringifiedEpochTimeUnitSeconds {
    fn from(s: String) -> Self {
        StringifiedEpochTimeUnitSeconds::StringValue(s)
    }
}