rsheet_lib 0.2.0

Libraries to help implementing cs6991-24T1-ass2
Documentation
//! The `CellValue` module contains the `CellValue` enum which represents the different types of values that a cell can have.
use serde::{Deserialize, Serialize};

use std::fmt::{self, Display, Formatter};

/// The `CellValue` enum represents the value of a cell.
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Clone)]
#[serde(untagged)]
pub enum CellValue {
    /// Represents an integer value.
    Int(i64),
    /// Represents a string value.
    String(String),
    /// Represents an error that a Cell has produced.
    Error(String),
    /// Represents an empty cell, this is the default value.
    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,
        }
    }
}