rgwml 2.0.0

Typed, local-first tabular data library with columnar in-memory storage.
Documentation
use std::fmt;

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
    Schema(String),
    ColumnNotFound(String),
    TypeMismatch { expected: String, actual: String },
    InvalidSelection(String),
    InvalidArgument(String),
    Unsupported(String),
    NotImplemented(&'static str),
    Io(String),
    Parse(String),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Schema(message) => write!(f, "schema error: {message}"),
            Self::ColumnNotFound(name) => write!(f, "column not found: {name}"),
            Self::TypeMismatch { expected, actual } => {
                write!(f, "type mismatch: expected {expected}, got {actual}")
            }
            Self::InvalidSelection(message) => write!(f, "invalid selection: {message}"),
            Self::InvalidArgument(message) => write!(f, "invalid argument: {message}"),
            Self::Unsupported(message) => write!(f, "unsupported: {message}"),
            Self::NotImplemented(message) => write!(f, "not implemented: {message}"),
            Self::Io(message) => write!(f, "io error: {message}"),
            Self::Parse(message) => write!(f, "parse error: {message}"),
        }
    }
}

impl std::error::Error for Error {}

impl From<std::io::Error> for Error {
    fn from(value: std::io::Error) -> Self {
        Self::Io(value.to_string())
    }
}

impl From<csv::Error> for Error {
    fn from(value: csv::Error) -> Self {
        Self::Io(value.to_string())
    }
}

pub type Result<T> = std::result::Result<T, Error>;