umya_spreadsheet/structs/
double_value.rs

1#[derive(Clone, Default, Debug, PartialEq, PartialOrd)]
2pub struct DoubleValue {
3    value: Option<f64>,
4}
5impl DoubleValue {
6    #[inline]
7    pub(crate) fn get_value(&self) -> &f64 {
8        match &self.value {
9            Some(v) => v,
10            None => &0f64,
11        }
12    }
13
14    #[inline]
15    pub(crate) fn get_value_string(&self) -> String {
16        self.get_value().to_string()
17    }
18
19    #[inline]
20    pub(crate) fn set_value(&mut self, value: f64) -> &mut Self {
21        self.value = Some(value);
22        self
23    }
24
25    #[inline]
26    pub(crate) fn set_value_string<S: Into<String>>(&mut self, value: S) -> &mut Self {
27        self.set_value(value.into().parse::<f64>().unwrap_or_default())
28    }
29
30    #[inline]
31    pub(crate) fn has_value(&self) -> bool {
32        self.value.is_some()
33    }
34
35    #[inline]
36    pub(crate) fn get_hash_string(&self) -> String {
37        if self.has_value() {
38            return self.get_value_string();
39        }
40        String::from("empty!!")
41    }
42}