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