From bf9b81e669f4ce98c8d58df5d776ae90726d7ec2 Mon Sep 17 00:00:00 2001 From: zirkonya Date: Sat, 29 Aug 2026 22:11:23 +0200 Subject: Add transport layer --- src/codec/error.rs | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'src/codec/error.rs') diff --git a/src/codec/error.rs b/src/codec/error.rs index c1bd4f7..7d88d55 100644 --- a/src/codec/error.rs +++ b/src/codec/error.rs @@ -1,37 +1,24 @@ -use std::fmt::Display; +use thiserror::Error; -// TODO : better error (using thiserror) +#[derive(Debug, Error)] +pub enum CodecError { + #[error("io error: {0}")] + IoError(#[from] std::io::Error), -#[derive(Debug)] -pub enum Error { - IoError(std::io::Error), + #[error("{0}")] Custom(String), } -impl std::error::Error for Error {} +pub type Result = core::result::Result; -impl Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{self:?}") - } -} - -pub type Result = core::result::Result; - -impl From for Error { - fn from(value: std::io::Error) -> Self { - Self::IoError(value) +impl From<&str> for CodecError { + fn from(value: &str) -> Self { + Self::Custom(value.to_string()) } } -impl From for Error { +impl From for CodecError { fn from(value: String) -> Self { Self::Custom(value) } } - -impl From<&str> for Error { - fn from(value: &str) -> Self { - Self::Custom(value.to_string()) - } -} -- cgit v1.2.3