From 4c74dacbc139ab14b85f8763402975ed7b92a96f Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Mon, 7 Oct 2024 15:57:02 +0200 Subject: [PATCH 1/3] impl core::error::Error under a feature --- stratum-v1/Cargo.toml | 3 ++- stratum-v1/src/error.rs | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/stratum-v1/Cargo.toml b/stratum-v1/Cargo.toml index 0f4d208..356a837 100644 --- a/stratum-v1/Cargo.toml +++ b/stratum-v1/Cargo.toml @@ -24,10 +24,11 @@ serde = { workspace = true } serde-json-core = { workspace = true, features = ["custom-error-messages"] } [features] +core-error = [] # bump MSRV to 1.81.0 defmt-03 = [ "dep:defmt", "embedded-io-async/defmt-03", - # "faster-hex/defmt-03", # will enable it after faster-hex publish PR#54 + # "faster-hex/defmt-03", # will enable it after faster-hex publish 0.11 "heapless/defmt-03", "serde-json-core/defmt", ] diff --git a/stratum-v1/src/error.rs b/stratum-v1/src/error.rs index 66b4fc3..f97606c 100644 --- a/stratum-v1/src/error.rs +++ b/stratum-v1/src/error.rs @@ -73,9 +73,11 @@ pub enum Error { HexError(faster_hex::Error), } -// impl core::error::Error for Error {} +#[cfg(feature = "core-error")] +impl core::error::Error for Error {} -impl core::fmt::Display for Error { +#[cfg(feature = "core-error")] +impl core::fmt::Display for Error { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{self:?}") } From b536e49781388c1d4d8c61cc1db30c26d765a4d8 Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Mon, 7 Oct 2024 16:00:25 +0200 Subject: [PATCH 2/3] Rename NetworkError into Network --- stratum-v1/src/client/mod.rs | 10 +++------- stratum-v1/src/error.rs | 8 ++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/stratum-v1/src/client/mod.rs b/stratum-v1/src/client/mod.rs index 43bd163..b9912c2 100644 --- a/stratum-v1/src/client/mod.rs +++ b/stratum-v1/src/client/mod.rs @@ -189,16 +189,12 @@ impl core::error::Error for Error {} +impl core::error::Error for Error {} #[cfg(feature = "core-error")] -impl core::fmt::Display for Error { +impl core::fmt::Display for Error { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{self:?}") } From 11e7e81d23ff8a2ea87805f3048bc30f4ef0dcbf Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Wed, 20 Nov 2024 18:02:56 +0100 Subject: [PATCH 3/3] use rustversion to avoid an extra feature --- Cargo.toml | 1 + stratum-v1/Cargo.toml | 2 +- stratum-v1/src/error.rs | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f6dcfd6..4cf5e79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ minicbor = { version = "0.24", features = ["derive"] } nom = { version = "7", default-features = false } phf = { version = "0.11", features = ["macros"], default-features = false } rand_xoshiro = "0.6" +rustversion = "1.0" secp256k1 = { version = "0.29", default-features = false } serde = { version = "1.0.156", features = ["derive"], default-features = false } serde_json = "1" diff --git a/stratum-v1/Cargo.toml b/stratum-v1/Cargo.toml index 356a837..9aeb698 100644 --- a/stratum-v1/Cargo.toml +++ b/stratum-v1/Cargo.toml @@ -20,11 +20,11 @@ embedded-io-async = { workspace = true } faster-hex = { version = "0.10", default-features = false } heapless = { workspace = true, features = ["serde"] } log = { workspace = true, optional = true } +rustversion = { workspace = true } serde = { workspace = true } serde-json-core = { workspace = true, features = ["custom-error-messages"] } [features] -core-error = [] # bump MSRV to 1.81.0 defmt-03 = [ "dep:defmt", "embedded-io-async/defmt-03", diff --git a/stratum-v1/src/error.rs b/stratum-v1/src/error.rs index 96ea516..5c1d1a1 100644 --- a/stratum-v1/src/error.rs +++ b/stratum-v1/src/error.rs @@ -73,10 +73,10 @@ pub enum Error { HexError(faster_hex::Error), } -#[cfg(feature = "core-error")] +#[rustversion::since(1.81)] impl core::error::Error for Error {} -#[cfg(feature = "core-error")] +#[rustversion::since(1.81)] impl core::fmt::Display for Error { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{self:?}")