Skip to content

Commit

Permalink
replace derive_more's 'From' in core
Browse files Browse the repository at this point in the history
  • Loading branch information
pkhry committed May 22, 2024
1 parent 7d753bc commit 885bbb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 10 additions & 7 deletions core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")]
Expand Down Expand Up @@ -38,11 +38,14 @@ pub enum Error {
#[cfg(feature = "std")]
impl std::error::Error for Error {}

impl From<scale_decode::visitor::DecodeError> 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)]
Expand Down
10 changes: 10 additions & 0 deletions core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

0 comments on commit 885bbb3

Please sign in to comment.