evalexpr/value/
value_type.rs

1use crate::Value;
2
3use super::numeric_types::EvalexprNumericTypes;
4
5/// The type of a `Value`.
6#[derive(Clone, Copy, Eq, PartialEq, Debug)]
7pub enum ValueType {
8    /// The `Value::String` type.
9    String,
10    /// The `Value::Float` type.
11    Float,
12    /// The `Value::Int` type.
13    Int,
14    /// The `Value::Boolean` type.
15    Boolean,
16    /// The `Value::Tuple` type.
17    Tuple,
18    /// The `Value::Empty` type.
19    Empty,
20}
21
22impl<NumericTypes: EvalexprNumericTypes> From<&Value<NumericTypes>> for ValueType {
23    fn from(value: &Value<NumericTypes>) -> Self {
24        match value {
25            Value::String(_) => ValueType::String,
26            Value::Float(_) => ValueType::Float,
27            Value::Int(_) => ValueType::Int,
28            Value::Boolean(_) => ValueType::Boolean,
29            Value::Tuple(_) => ValueType::Tuple,
30            Value::Empty => ValueType::Empty,
31        }
32    }
33}
34
35impl<NumericTypes: EvalexprNumericTypes> From<&mut Value<NumericTypes>> for ValueType {
36    fn from(value: &mut Value<NumericTypes>) -> Self {
37        From::<&Value<NumericTypes>>::from(value)
38    }
39}
40
41impl<NumericTypes: EvalexprNumericTypes> From<&&mut Value<NumericTypes>> for ValueType {
42    fn from(value: &&mut Value<NumericTypes>) -> Self {
43        From::<&Value<NumericTypes>>::from(*value)
44    }
45}