karyon_eventemitter/
error.rs1pub type Result<T> = std::result::Result<T, Error>;
2
3#[derive(Debug)]
4pub enum Error {
5 IO(std::io::Error),
6
7 EventEmitter(String),
8
9 ChannelSend(String),
10 ChannelRecv(async_channel::RecvError),
11}
12
13impl std::error::Error for Error {}
14
15impl std::fmt::Display for Error {
16 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
17 match self {
18 Self::IO(io) => write!(f, "IO error: {io}"),
19 Self::EventEmitter(err) => write!(f, "Event emitter error: {err}"),
20 Self::ChannelSend(err) => write!(f, "Async channel send error: {err}"),
21 Self::ChannelRecv(err) => write!(f, "Async channel recv error: {err}"),
22 }
23 }
24}
25
26impl From<std::io::Error> for Error {
27 fn from(error: std::io::Error) -> Self {
28 Error::IO(error)
29 }
30}
31
32impl From<async_channel::RecvError> for Error {
33 fn from(error: async_channel::RecvError) -> Self {
34 Error::ChannelRecv(error)
35 }
36}
37
38impl<T> From<async_channel::SendError<T>> for Error {
39 fn from(error: async_channel::SendError<T>) -> Self {
40 Error::ChannelSend(error.to_string())
41 }
42}