openformula_kernel/
value.rs1use alloc::string::String;
2use alloc::vec::Vec;
3
4use crate::{CalcError, Number};
5
6#[derive(Clone, Debug, PartialEq)]
8pub enum Value {
9 Number(Number),
11 Text(String),
13 Boolean(bool),
15 Empty,
17 Error(CalcError),
19}
20
21impl From<Number> for Value {
22 fn from(value: Number) -> Self {
23 Self::Number(value)
24 }
25}
26
27impl From<i64> for Value {
28 fn from(value: i64) -> Self {
29 Self::Number(Number::from_i64(value))
30 }
31}
32
33impl From<bool> for Value {
34 fn from(value: bool) -> Self {
35 Self::Boolean(value)
36 }
37}
38
39impl From<String> for Value {
40 fn from(value: String) -> Self {
41 Self::Text(value)
42 }
43}
44
45impl From<&str> for Value {
46 fn from(value: &str) -> Self {
47 Self::Text(value.into())
48 }
49}
50
51impl From<CalcError> for Value {
52 fn from(value: CalcError) -> Self {
53 Self::Error(value)
54 }
55}
56
57#[derive(Clone, Debug, PartialEq)]
59pub enum Argument {
60 Scalar(Value),
62 Range(Vec<Value>),
64 Missing,
66}
67
68impl Argument {
69 #[must_use]
71 pub fn scalar(value: impl Into<Value>) -> Self {
72 Self::Scalar(value.into())
73 }
74
75 #[must_use]
77 pub fn range(values: impl IntoIterator<Item = Value>) -> Self {
78 Self::Range(values.into_iter().collect())
79 }
80}
81
82impl From<Value> for Argument {
83 fn from(value: Value) -> Self {
84 Self::Scalar(value)
85 }
86}