oxilean_kernel/serial/
oleanerror_traits.rs1use super::functions::*;
15use super::types::OleanError;
16use std::fmt;
17
18impl fmt::Display for OleanError {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 match self {
21 OleanError::InvalidMagic => {
22 write!(f, "invalid OleanC magic bytes (expected 'OLNC')")
23 }
24 OleanError::UnsupportedVersion(v) => {
25 write!(f, "unsupported OleanC version: {v} (supported: {VERSION})")
26 }
27 OleanError::UnexpectedEof => {
28 write!(f, "unexpected end of file while reading OleanC data")
29 }
30 OleanError::InvalidUtf8(e) => {
31 write!(f, "invalid UTF-8 in OleanC string: {e}")
32 }
33 OleanError::InvalidDeclKind(k) => {
34 write!(f, "invalid declaration kind tag: {k}")
35 }
36 OleanError::IoError(e) => write!(f, "I/O error: {e}"),
37 }
38 }
39}
40
41impl std::error::Error for OleanError {}
42
43impl From<std::io::Error> for OleanError {
44 fn from(e: std::io::Error) -> Self {
45 OleanError::IoError(e)
46 }
47}
48
49impl From<std::string::FromUtf8Error> for OleanError {
50 fn from(e: std::string::FromUtf8Error) -> Self {
51 OleanError::InvalidUtf8(e)
52 }
53}