use alloc::string::String;
use alloc::vec::Vec;
use crate::{CalcError, Number};
#[derive(Clone, Debug, PartialEq)]
pub enum Value {
Number(Number),
Text(String),
Boolean(bool),
Empty,
Error(CalcError),
}
impl From<Number> for Value {
fn from(value: Number) -> Self {
Self::Number(value)
}
}
impl From<i64> for Value {
fn from(value: i64) -> Self {
Self::Number(Number::from_i64(value))
}
}
impl From<bool> for Value {
fn from(value: bool) -> Self {
Self::Boolean(value)
}
}
impl From<String> for Value {
fn from(value: String) -> Self {
Self::Text(value)
}
}
impl From<&str> for Value {
fn from(value: &str) -> Self {
Self::Text(value.into())
}
}
impl From<CalcError> for Value {
fn from(value: CalcError) -> Self {
Self::Error(value)
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum Argument {
Scalar(Value),
Range(Vec<Value>),
Missing,
}
impl Argument {
#[must_use]
pub fn scalar(value: impl Into<Value>) -> Self {
Self::Scalar(value.into())
}
#[must_use]
pub fn range(values: impl IntoIterator<Item = Value>) -> Self {
Self::Range(values.into_iter().collect())
}
}
impl From<Value> for Argument {
fn from(value: Value) -> Self {
Self::Scalar(value)
}
}