1*7b32f508SLoGin use std::{error::Error, fmt::Display}; 2*7b32f508SLoGin 3*7b32f508SLoGin #[derive(Debug)] 4*7b32f508SLoGin pub enum BackendErrorKind { 5*7b32f508SLoGin FileNotFound, 6*7b32f508SLoGin KernelLoadError, 7*7b32f508SLoGin } 8*7b32f508SLoGin 9*7b32f508SLoGin #[derive(Debug)] 10*7b32f508SLoGin pub struct BackendError { 11*7b32f508SLoGin kind: BackendErrorKind, 12*7b32f508SLoGin message: Option<String>, 13*7b32f508SLoGin } 14*7b32f508SLoGin 15*7b32f508SLoGin impl BackendError { new(kind: BackendErrorKind, message: Option<String>) -> Self16*7b32f508SLoGin pub fn new(kind: BackendErrorKind, message: Option<String>) -> Self { 17*7b32f508SLoGin Self { kind, message } 18*7b32f508SLoGin } 19*7b32f508SLoGin } 20*7b32f508SLoGin 21*7b32f508SLoGin impl Error for BackendError {} 22*7b32f508SLoGin 23*7b32f508SLoGin impl Display for BackendError { fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result24*7b32f508SLoGin fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 25*7b32f508SLoGin match &self.kind { 26*7b32f508SLoGin BackendErrorKind::FileNotFound => { 27*7b32f508SLoGin write!(f, "File not found: {:?}", self.message.as_ref().unwrap()) 28*7b32f508SLoGin } 29*7b32f508SLoGin BackendErrorKind::KernelLoadError => { 30*7b32f508SLoGin write!( 31*7b32f508SLoGin f, 32*7b32f508SLoGin "Failed to load kernel: {:?}", 33*7b32f508SLoGin self.message.as_ref().unwrap() 34*7b32f508SLoGin ) 35*7b32f508SLoGin } 36*7b32f508SLoGin } 37*7b32f508SLoGin } 38*7b32f508SLoGin } 39