opensearch-client 0.3.2

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

$$DOCUMENTATION$$

#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[serde(untagged)]
pub enum $$NAME$$ {
    $$SINGLEVALUE$$(String),
    $$ARRAYVALUE$$(Vec<String>),
}

impl std::fmt::Display for $$NAME$$ {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            $$NAME$$::$$SINGLEVALUE$$(s) => write!(f, "{}", s),
            $$NAME$$::$$ARRAYVALUE$$(v) => write!(f, "{}", v.join(",")),
        }
    }
}


impl $$NAME$$ {
    pub fn as_vec(&self) -> Vec<String> {
        match self {
            $$NAME$$::$$SINGLEVALUE$$(s) => vec![s.clone()],
            $$NAME$$::$$ARRAYVALUE$$(v) => v.clone(),
        }
    }
}

impl Default for $$NAME$$ {
    fn default() -> Self {
        $$NAME$$::$$ARRAYVALUE$$(Vec::new())
    }
}

// Allow constructing $$NAME$$ from String
impl From<String> for $$NAME$$ {
    fn from(s: String) -> Self {
        $$NAME$$::$$SINGLEVALUE$$(s)
    }
}

// Allow constructing $$NAME$$ from &str
impl From<&str> for $$NAME$$ {
    fn from(s: &str) -> Self {
        $$NAME$$::$$SINGLEVALUE$$(s.to_string())
    }
}

// Allow constructing $$NAME$$ from Vec<String>
impl From<Vec<String>> for $$NAME$$ {
    fn from(v: Vec<String>) -> Self {
        $$NAME$$::$$ARRAYVALUE$$(v)
    }
}

// Allow constructing $$NAME$$ from Vec<&str>
impl From<Vec<&str>> for $$NAME$$ {
    fn from(v: Vec<&str>) -> Self {
        $$NAME$$::$$ARRAYVALUE$$(v.into_iter().map(|s| s.to_string()).collect())
    }
}