Skip to main content

yuzu_core/
error.rs

1//! [`EngineError`]: shape violations from panel construction and evaluation failures.
2
3use std::fmt;
4
5#[derive(Debug)]
6pub enum EngineError {
7    ShapeMismatch {
8        rows: usize,
9        cols: usize,
10        data_len: usize,
11    },
12    Eval(String),
13}
14
15impl fmt::Display for EngineError {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match self {
18            EngineError::ShapeMismatch {
19                rows,
20                cols,
21                data_len,
22            } => {
23                write!(f, "shape mismatch: {rows}x{cols} != data len {data_len}")
24            }
25            EngineError::Eval(m) => write!(f, "eval error: {m}"),
26        }
27    }
28}
29
30impl std::error::Error for EngineError {}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35
36    #[test]
37    fn display_messages() {
38        let e = EngineError::ShapeMismatch {
39            rows: 1,
40            cols: 2,
41            data_len: 3,
42        };
43        assert!(e.to_string().contains("shape mismatch"));
44        assert!(EngineError::Eval("boom".into())
45            .to_string()
46            .contains("boom"));
47    }
48}