Skip to main content

opensearch_client/common/
stringified_long.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#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13#[serde(untagged)]
14pub enum StringifiedLong {
15    StringValue(String),
16    IntegerValue(i64),
17}
18
19impl std::fmt::Display for StringifiedLong {
20    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21        match self {
22            StringifiedLong::StringValue(s) => write!(f, "{}", s),
23            StringifiedLong::IntegerValue(n) => write!(f, "{}", n),
24        }
25    }
26}
27
28impl StringifiedLong {
29    pub fn as_str(&self) -> String {
30        match self {
31            StringifiedLong::StringValue(s) => s.clone(),
32            StringifiedLong::IntegerValue(n) => n.to_string(),
33        }
34    }
35
36    pub fn as_num(&self) -> Option<i64> {
37        match self {
38            StringifiedLong::IntegerValue(n) => Some(*n),
39            _ => None,
40        }
41    }
42}
43
44impl From<i64> for StringifiedLong {
45    fn from(n: i64) -> Self {
46        StringifiedLong::IntegerValue(n)
47    }
48}
49
50impl From<&str> for StringifiedLong {
51    fn from(s: &str) -> Self {
52        StringifiedLong::StringValue(s.to_string())
53    }
54}
55
56impl From<String> for StringifiedLong {
57    fn from(s: String) -> Self {
58        StringifiedLong::StringValue(s)
59    }
60}