radar-g/radarg_plugin_interface/src/error.rs
2024-01-29 00:45:50 +08:00

50 lines
1.1 KiB
Rust

use abi_stable::{
std_types::{ RBoxError, RVec},
StableAbi,
};
use std::{
error::Error as ErrorTrait,
fmt::{self, Display},
};
#[repr(u8)]
#[derive(Debug, StableAbi)]
pub enum Error {
UnsupportedFormat,
FileError(RBoxError),
Custom(RBoxError),
/// A list of errors.
Many(RVec<Error>),
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::UnsupportedFormat => {
writeln!(
f,
"Plugin ooes not support this command:\n\
\t\n\
Because of this error:\n\n\
Supported commands:\
"
)?;
Ok(())
},
Error::Custom(e) => Display::fmt(e, f),
Error::Many(list) => {
for e in list {
writeln!(f, "{}", e)?;
}
Ok(())
},
_ => { Ok(())}
}
}
}
impl ErrorTrait for Error {}