wagahai_lut 0.1.0

CUBE LUT parser and image processing library with SIMD
Documentation
/*
 * SPDX-FileCopyrightText: © 2026 Jinwoo Park (pmnxis@gmail.com)
 *
 * SPDX-License-Identifier: MIT
 */

//! Error types for wagahai_lut

use std::io;
use thiserror::Error;

/// Result type alias for wagahai_lut operations
pub type Result<T> = std::result::Result<T, CubeError>;

/// Errors that can occur during CUBE LUT parsing and processing
#[derive(Error, Debug)]
pub enum CubeError {
    #[error("I/O error: {0}")]
    Io(#[from] io::Error),

    #[error("Failed to parse number: {0}")]
    ParseFloat(#[from] std::num::ParseFloatError),

    #[error("Failed to parse integer: {0}")]
    ParseInt(#[from] std::num::ParseIntError),

    #[error("Invalid file format: {0}")]
    InvalidFormat(String),

    #[error("Unknown or repeated keyword: {0}")]
    UnknownOrRepeatedKeyword(String),

    #[error("Title missing quote")]
    TitleMissingQuote,

    #[error("Domain bounds reversed: min >= max")]
    DomainBoundsReversed,

    #[error("LUT size out of range: {size}, expected: {min}-{max}")]
    LutSizeOutOfRange { size: usize, min: usize, max: usize },

    #[error("Could not parse table data: {0}")]
    CouldNotParseTableData(String),

    #[error("Premature end of file")]
    PrematureEndOfFile,

    #[error("Tried Invalid channel images on this LUT")]
    InvalidChannel,

    #[error("Line too long: {len} bytes (max: 250)")]
    LineTooLong { len: usize },

    #[error("Unsupported LUT type: {0}")]
    UnsupportedLutType(String),

    #[error("Image processing error: {0}")]
    ImageProcessingError(String),

    #[error("Invalid image dimensions")]
    InvalidDimensions,

    #[error("Index out of bounds: {index} >= {len}")]
    IndexOutOfBounds { index: usize, len: usize },
}

impl CubeError {
    /// Check if this is an I/O error
    pub fn is_io_error(&self) -> bool {
        matches!(self, CubeError::Io(_))
    }

    /// Check if this is a parsing error
    pub fn is_parse_error(&self) -> bool {
        matches!(
            self,
            CubeError::ParseFloat(_)
                | CubeError::ParseInt(_)
                | CubeError::InvalidFormat(_)
                | CubeError::CouldNotParseTableData(_)
        )
    }

    /// Check if this is a format/validation error
    pub fn is_format_error(&self) -> bool {
        matches!(
            self,
            CubeError::UnknownOrRepeatedKeyword(_)
                | CubeError::TitleMissingQuote
                | CubeError::DomainBoundsReversed
                | CubeError::LutSizeOutOfRange { .. }
                | CubeError::UnsupportedLutType(_)
        )
    }
}