From 885bbb3a9b8ad3484e6b92d6366440a7abbf9eb2 Mon Sep 17 00:00:00 2001 From: Pavlo Khrystenko Date: Tue, 21 May 2024 17:45:19 +0200 Subject: [PATCH] replace derive_more's 'From' in core --- core/src/error.rs | 17 ++++++++++------- core/src/macros.rs | 10 ++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/core/src/error.rs b/core/src/error.rs index f9f8b0a629..6e9e890286 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -6,11 +6,11 @@ use alloc::boxed::Box; use alloc::string::String; -use derive_more::{Display, From}; +use derive_more::Display; use subxt_metadata::StorageHasher; /// The error emitted when something goes wrong. -#[derive(Debug, Display, From)] +#[derive(Debug, Display)] pub enum Error { /// Codec error. #[display(fmt = "Scale codec error: {_0}")] @@ -38,11 +38,14 @@ pub enum Error { #[cfg(feature = "std")] impl std::error::Error for Error {} -impl From for Error { - fn from(value: scale_decode::visitor::DecodeError) -> Self { - Error::Decode(value.into()) - } -} +convert_error!(ExtrinsicParamsError as Error::ExtrinsicParams); +convert_error!(BlockError as Error::Block); +convert_error!(MetadataError as Error::Metadata); +convert_error!(scale_decode::Error as Error::Decode); +convert_error!(scale_decode::visitor::DecodeError as Error::Decode); +convert_error!(scale_encode::Error as Error::Encode); +convert_error!(StorageAddressError as Error::StorageAddress); +convert_error!(codec::Error as Error::Codec); /// Block error #[derive(Clone, Debug, Display, Eq, PartialEq)] diff --git a/core/src/macros.rs b/core/src/macros.rs index 8e25742c88..d727ba7233 100644 --- a/core/src/macros.rs +++ b/core/src/macros.rs @@ -18,4 +18,14 @@ macro_rules! cfg_substrate_compat { }; } +macro_rules! convert_error { + ($module_path:path as $delegate_ty:ident :: $variant:ident) => { + impl From<$module_path> for $delegate_ty { + fn from(val: $module_path) -> Self { + $delegate_ty::$variant(val.into()) + } + } + }; +} + pub(crate) use {cfg_feature, cfg_substrate_compat};