diff options
author | hozan23 <hozan23@proton.me> | 2023-11-18 00:54:09 +0300 |
---|---|---|
committer | hozan23 <hozan23@proton.me> | 2023-11-18 00:54:09 +0300 |
commit | ce82eb571b0f48a59f3a94cf61af9ccd1beea438 (patch) | |
tree | bd8ce05fade23455033d878a2781991af3326fa8 /core/src | |
parent | f04ba793bbc15d021444c5010aaf0e4bae655ce0 (diff) |
clean up error module and use `transparent` attribute
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/error.rs | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/core/src/error.rs b/core/src/error.rs index 15947c8..63b45d3 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -4,7 +4,7 @@ pub type Result<T> = std::result::Result<T, Error>; #[derive(ThisError, Debug)] pub enum Error { - #[error("IO Error: {0}")] + #[error(transparent)] IO(#[from] std::io::Error), #[error("Timeout Error")] @@ -16,14 +16,14 @@ pub enum Error { #[error("Channel Send Error: {0}")] ChannelSend(String), - #[error("Channel Receive Error: {0}")] - ChannelRecv(String), + #[error(transparent)] + ChannelRecv(#[from] smol::channel::RecvError), - #[error("Decode Error: {0}")] - Decode(String), + #[error(transparent)] + BincodeDecode(#[from] bincode::error::DecodeError), - #[error("Encode Error: {0}")] - Encode(String), + #[error(transparent)] + BincodeEncode(#[from] bincode::error::EncodeError), } impl<T> From<smol::channel::SendError<T>> for Error { @@ -31,21 +31,3 @@ impl<T> From<smol::channel::SendError<T>> for Error { Error::ChannelSend(error.to_string()) } } - -impl From<smol::channel::RecvError> for Error { - fn from(error: smol::channel::RecvError) -> Self { - Error::ChannelRecv(error.to_string()) - } -} - -impl From<bincode::error::DecodeError> for Error { - fn from(error: bincode::error::DecodeError) -> Self { - Error::Decode(error.to_string()) - } -} - -impl From<bincode::error::EncodeError> for Error { - fn from(error: bincode::error::EncodeError) -> Self { - Error::Encode(error.to_string()) - } -} |