Skip to main content

oxilean_kernel/error/
kernelerror_traits.rs

1//! # KernelError - Trait Implementations
2//!
3//! This module contains trait implementations for `KernelError`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//! - `Error`
9//! - `From`
10//! - `From`
11//!
12//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
13
14use super::types::KernelError;
15use std::fmt;
16
17impl fmt::Display for KernelError {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            KernelError::TypeMismatch {
21                expected,
22                got,
23                context,
24            } => {
25                write!(
26                    f,
27                    "type mismatch in {}: expected {}, got {}",
28                    context, expected, got
29                )
30            }
31            KernelError::UnboundVariable(idx) => write!(f, "unbound variable: #{}", idx),
32            KernelError::UnknownConstant(name) => write!(f, "unknown constant: {}", name),
33            KernelError::UniverseInconsistency { lhs, rhs } => {
34                write!(f, "universe inconsistency: {} vs {}", lhs, rhs)
35            }
36            KernelError::InvalidInductive(msg) => {
37                write!(f, "invalid inductive type: {}", msg)
38            }
39            KernelError::InvalidRecursor(msg) => write!(f, "invalid recursor: {}", msg),
40            KernelError::NotASort(expr) => write!(f, "not a sort: {}", expr),
41            KernelError::NotAFunction(expr) => write!(f, "not a function type: {}", expr),
42            KernelError::InductiveError(msg) => write!(f, "inductive error: {}", msg),
43            KernelError::Other(msg) => write!(f, "{}", msg),
44        }
45    }
46}
47
48impl std::error::Error for KernelError {}
49
50impl From<String> for KernelError {
51    fn from(s: String) -> Self {
52        KernelError::Other(s)
53    }
54}
55
56impl From<&str> for KernelError {
57    fn from(s: &str) -> Self {
58        KernelError::Other(s.to_string())
59    }
60}