Skip to content

Commit

Permalink
feat: switch all std::error to core::error (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Nov 28, 2024
1 parent d6ab70d commit 6fff20a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions crates/dyn-abi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ impl From<alloc::collections::TryReserveError> 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),
Expand Down
8 changes: 4 additions & 4 deletions crates/primitives/src/bits/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ impl From<hex::FromHexError> 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,
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/primitives/src/signature/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ impl From<hex::FromHexError> 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,
}
Expand Down
8 changes: 4 additions & 4 deletions crates/primitives/src/signed/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ impl From<ruint::ParseError> 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,
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions crates/primitives/src/utils/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 2 additions & 3 deletions crates/sol-types/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 6fff20a

Please sign in to comment.