From 2ab76fd71fb3cb49747c0fb244ac775e503d7c24 Mon Sep 17 00:00:00 2001 From: Ricardo Delfin Date: Sat, 21 Jun 2025 17:42:31 +0100 Subject: [PATCH] Switched error to use thiserror --- rpos_drv/Cargo.toml | 2 +- rpos_drv/src/errors.rs | 26 ++++++++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/rpos_drv/Cargo.toml b/rpos_drv/Cargo.toml index e8d6cec..715945d 100644 --- a/rpos_drv/Cargo.toml +++ b/rpos_drv/Cargo.toml @@ -9,4 +9,4 @@ authors = ["Tony Huang "] edition = "2018" [dependencies] -failure = "0.1.5" +thiserror = "2.0" diff --git a/rpos_drv/src/errors.rs b/rpos_drv/src/errors.rs index a1931d7..beedf8a 100644 --- a/rpos_drv/src/errors.rs +++ b/rpos_drv/src/errors.rs @@ -1,30 +1,24 @@ -pub use failure::{ Fail, Error }; - -#[derive(Fail, Debug)] +#[derive(thiserror::Error, Debug)] pub enum RposError { /// The execution of operation failed - #[fail(display="operation failed: {}", description)] - OperationFail { - description: String - }, + #[error("operation failed: {}", description)] + OperationFail { description: String }, /// The execution of operation is timed out - #[fail(display="operation timeout")] + #[error("operation timeout")] OperationTimeout, /// The device doesn't support this operation - #[fail(display="operation not support")] + #[error("operation not support")] OperationNotSupport, /// The decoding data is invalid according to current protocol - #[fail(display="protocol error: {}", description)] - ProtocolError { - description: String - }, + #[error("protocol error: {}", description)] + ProtocolError { description: String }, /// The buffer is too small for message encoding - #[fail(display="buffer is too small for message encoding")] - BufferTooSmall + #[error("buffer is too small for message encoding")] + BufferTooSmall, } -pub type Result = std::result::Result; +pub type Result = std::result::Result;