Skip to main content

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