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

/// FieldDateMath
/// A date range limit, represented either as a DateMath expression or a number expressed
/// according to the target field's precision.

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FieldDateMath {
    DateMathValue(String),
    ValueValue(u64),
}

impl Default for FieldDateMath {
    fn default() -> Self {
        FieldDateMath::ValueValue(0)
    }
}

impl std::fmt::Display for FieldDateMath {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            FieldDateMath::DateMathValue(val) => write!(f, "{}", val),
            FieldDateMath::ValueValue(val) => write!(f, "{}", val),
        }
    }
}
impl FieldDateMath {
    pub fn as_str(&self) -> String {
        match self {
            FieldDateMath::DateMathValue(s) => s.clone(),
            FieldDateMath::ValueValue(n) => n.to_string(),
        }
    }

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