Skip to main content

trit_vsa/
error.rs

1//! Error types for ternary-rs.
2
3use thiserror::Error;
4
5/// Result type alias for ternary-rs operations.
6pub type Result<T> = std::result::Result<T, TernaryError>;
7
8/// Errors that can occur during ternary operations.
9#[derive(Debug, Error)]
10pub enum TernaryError {
11    /// Invalid value for ternary conversion.
12    #[error("invalid ternary value: {0} (expected -1, 0, or +1)")]
13    InvalidValue(i32),
14
15    /// Dimension mismatch in vector operations.
16    #[error("dimension mismatch: expected {expected}, got {actual}")]
17    DimensionMismatch {
18        /// Expected dimension.
19        expected: usize,
20        /// Actual dimension.
21        actual: usize,
22    },
23
24    /// Index out of bounds.
25    #[error("index {index} out of bounds for size {size}")]
26    IndexOutOfBounds {
27        /// The index that was accessed.
28        index: usize,
29        /// The size of the container.
30        size: usize,
31    },
32
33    /// Overflow in ternary arithmetic.
34    #[error("arithmetic overflow: value {0} exceeds ternary range")]
35    Overflow(i64),
36
37    /// Invalid tryte value (must be in range -13 to +13).
38    #[error("invalid tryte value: {0} (expected -13 to +13)")]
39    InvalidTryteValue(i32),
40
41    /// Invalid word value (must be in range -364 to +364).
42    #[error("invalid word value: {0} (expected -364 to +364)")]
43    InvalidWordValue(i32),
44
45    /// Empty vector operation.
46    #[error("operation not supported on empty vector")]
47    EmptyVector,
48
49    /// GPU computation error (only available with cuda feature).
50    #[cfg(feature = "cuda")]
51    #[error("GPU computation error: {0}")]
52    GpuError(#[from] crate::gpu::traits::GpuError),
53}