use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Clone)]
#[serde(untagged)]
pub enum CellValue {
Int(i64),
String(String),
Error(String),
None,
}
impl Default for CellValue {
fn default() -> Self {
CellValue::None
}
}
impl Display for CellValue {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
CellValue::Int(i) => write!(f, "{}", i),
CellValue::String(s) => write!(f, "\"{}\"", s),
CellValue::Error(s) => write!(f, "Error: \"{}\"", s),
CellValue::None => write!(f, "None"),
}
}
}
impl CellValue {
pub fn is_error(&self) -> bool {
match self {
CellValue::Error(_) => true,
_ => false,
}
}
}