umya-spreadsheet 2.3.3

umya-spreadsheet is a library written in pure Rust to read and write xlsx file.
Documentation
use super::EnumTrait;
use std::str::FromStr;

#[derive(Clone, Default, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct EnumValue<T: EnumTrait + FromStr> {
    value: Option<T>,
    value_default: T,
}

impl<T: EnumTrait + FromStr> EnumValue<T> {
    #[inline]
    pub(crate) fn get_value(&self) -> &T {
        match &self.value {
            Some(v) => v,
            None => &self.value_default,
        }
    }

    #[inline]
    pub(crate) fn get_value_string(&self) -> &str {
        self.get_value().get_value_string()
    }

    #[inline]
    pub(crate) fn set_value(&mut self, value: T) -> &mut EnumValue<T> {
        self.value = Some(value);
        self
    }

    #[inline]
    pub(crate) fn set_value_string<S: Into<String>>(&mut self, value: S) -> &mut EnumValue<T> {
        if let Ok(v) = T::from_str(value.into().as_str()) {
            self.set_value(v);
        }
        self
    }

    #[inline]
    pub(crate) fn has_value(&self) -> bool {
        self.value.is_some()
    }

    #[inline]
    pub(crate) fn get_hash_string(&self) -> &str {
        if self.has_value() {
            return self.get_value_string();
        }
        "empty!!"
    }
}