From 6fff20a9b0c50c47af1741d3317f312761f6b107 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:47:32 +0100 Subject: [PATCH] feat: switch all std::error to core::error (#815) --- Cargo.toml | 3 ++- crates/dyn-abi/src/error.rs | 5 ++--- crates/primitives/src/bits/address.rs | 8 ++++---- crates/primitives/src/signature/error.rs | 8 ++++---- crates/primitives/src/signed/errors.rs | 8 ++++---- crates/primitives/src/utils/units.rs | 5 ++--- crates/sol-types/src/errors.rs | 5 ++--- 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 49c4ec410..65c60747b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -90,8 +90,9 @@ bytes = { version = "1", default-features = false } criterion = "0.5" derive_arbitrary = "1.3" getrandom = "0.2" -hex = { package = "const-hex", version = "1.10", default-features = false, features = [ +hex = { package = "const-hex", version = "1.14", default-features = false, features = [ "alloc", + "core-error", ] } itoa = "1" once_cell = "1" diff --git a/crates/dyn-abi/src/error.rs b/crates/dyn-abi/src/error.rs index 1b2893d05..bffba0dfe 100644 --- a/crates/dyn-abi/src/error.rs +++ b/crates/dyn-abi/src/error.rs @@ -98,10 +98,9 @@ impl From for Error { } } -#[cfg(feature = "std")] -impl std::error::Error for Error { +impl core::error::Error for Error { #[inline] - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::Hex(e) => Some(e), Self::TypeParser(e) => Some(e), diff --git a/crates/primitives/src/bits/address.rs b/crates/primitives/src/bits/address.rs index 230da393e..94cb3f417 100644 --- a/crates/primitives/src/bits/address.rs +++ b/crates/primitives/src/bits/address.rs @@ -22,13 +22,13 @@ impl From for AddressError { } } -#[cfg(feature = "std")] -impl std::error::Error for AddressError { +impl core::error::Error for AddressError { #[inline] - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { + #[cfg(any(feature = "std", not(feature = "hex-compat")))] Self::Hex(err) => Some(err), - Self::InvalidChecksum => None, + _ => None, } } } diff --git a/crates/primitives/src/signature/error.rs b/crates/primitives/src/signature/error.rs index a1e3dd226..400241e76 100644 --- a/crates/primitives/src/signature/error.rs +++ b/crates/primitives/src/signature/error.rs @@ -31,12 +31,12 @@ impl From for SignatureError { } } -#[cfg(feature = "std")] -impl std::error::Error for SignatureError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for SignatureError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { - #[cfg(feature = "k256")] + #[cfg(all(feature = "k256", feature = "std"))] Self::K256(e) => Some(e), + #[cfg(any(feature = "std", not(feature = "hex-compat")))] Self::FromHex(e) => Some(e), _ => None, } diff --git a/crates/primitives/src/signed/errors.rs b/crates/primitives/src/signed/errors.rs index 72a303f7b..f4ac02231 100644 --- a/crates/primitives/src/signed/errors.rs +++ b/crates/primitives/src/signed/errors.rs @@ -25,12 +25,12 @@ impl From for ParseSignedError { } } -#[cfg(feature = "std")] -impl std::error::Error for ParseSignedError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for ParseSignedError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { + #[cfg(feature = "std")] Self::Ruint(err) => Some(err), - Self::IntegerOverflow => None, + _ => None, } } } diff --git a/crates/primitives/src/utils/units.rs b/crates/primitives/src/utils/units.rs index cbb757e4e..7659e6ed6 100644 --- a/crates/primitives/src/utils/units.rs +++ b/crates/primitives/src/utils/units.rs @@ -98,9 +98,8 @@ pub enum UnitsError { ParseSigned(ParseSignedError), } -#[cfg(feature = "std")] -impl std::error::Error for UnitsError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for UnitsError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::InvalidUnit(_) => None, Self::ParseSigned(e) => Some(e), diff --git a/crates/sol-types/src/errors.rs b/crates/sol-types/src/errors.rs index a0cb0ba9a..8f3c7a9ee 100644 --- a/crates/sol-types/src/errors.rs +++ b/crates/sol-types/src/errors.rs @@ -74,9 +74,8 @@ pub enum Error { Other(Cow<'static, str>), } -#[cfg(feature = "std")] -impl std::error::Error for Error { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for Error { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::Reserve(e) => Some(e), Self::FromHexError(e) => Some(e),