Skip to content

Commit 7bb7ca3

Browse files
committed
implement core::error::Error
this trait has been stabilised in Rust 1.81.0. the existing custom `Error` types cannot be removed / replaced as that'd be a breaking change. for the same reason it's not possible for them to require `core::error::Error` being implemented. however, we can add an `impl core::error::Error for dyn Error` for every custom error type to provide an automatic coverage. HALs can still add an implementation for their specific error type if they wish to add more details (e.g. implement `source`). as `core::error::Error` requires `core::fmt::Display` to be implemented a simple blanket implementation has been added which prints the `Debug` output. existing `std` feature-gated implementations of `std::error::Error` have also been moved to `core::error::Error` and the feature gate removed. this raises the MSRV to 1.81.0 for most crates, but based on the MSRV policy this should not be an issue.
1 parent 0c31d81 commit 7bb7ca3

File tree

26 files changed

+89
-45
lines changed

26 files changed

+89
-45
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,9 @@ jobs:
3838
--target thumbv7m-none-eabi
3939
--features async,defmt-03
4040
41-
msrv-1-60:
41+
msrv-1-81:
4242
runs-on: ubuntu-latest
4343
steps:
4444
- uses: actions/checkout@v4
45-
- uses: dtolnay/[email protected]
46-
- run: >
47-
cargo test
48-
-p embedded-hal:1.0.0
49-
-p embedded-hal-bus
50-
-p embedded-hal-nb
51-
-p embedded-io
52-
-p embedded-io-adapters
53-
-p embedded-can
54-
55-
msrv-1-75:
56-
runs-on: ubuntu-latest
57-
steps:
58-
- uses: actions/checkout@v4
59-
- uses: dtolnay/[email protected]
45+
- uses: dtolnay/[email protected]
6046
- run: cargo test --workspace --all-features

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ on crates.io.
6464

6565
## Minimum Supported Rust Version (MSRV)
6666

67-
This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
67+
This crate is guaranteed to compile on stable Rust 1.81 and up. It *might*
6868
compile with older versions but that may change in any new patch release.
6969

7070
See [here](docs/msrv.md) for details on how the MSRV may be upgraded.

embedded-can/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
...
10+
- Added blanket `core::error::Error` and `core::fmt::Display` implementations for the custom `Error` traits
11+
- Increased MSRV to 1.81 due to `core::error::Error`
1112

1213
## [v0.4.1] - 2022-09-28
1314

embedded-can/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "embedded-can"
33
version = "0.4.1"
44
edition = "2021"
5-
rust-version = "1.56"
5+
rust-version = "1.81"
66

77
description = "HAL traits for Controller Area Network (CAN) devices."
88
categories = ["embedded", "hardware-support", "no-std"]

embedded-can/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This project is developed and maintained by the [HAL team](https://github.com/ru
1919

2020
## Minimum Supported Rust Version (MSRV)
2121

22-
This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
22+
This crate is guaranteed to compile on stable Rust 1.81 and up. It *might*
2323
compile with older versions but that may change in any new patch release.
2424

2525
See [here](../docs/msrv.md) for details on how the MSRV may be upgraded.

embedded-can/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ pub trait Error: core::fmt::Debug {
6161
fn kind(&self) -> ErrorKind;
6262
}
6363

64+
impl core::fmt::Display for dyn Error {
65+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
66+
write!(f, "{:?}", self)
67+
}
68+
}
69+
70+
impl core::error::Error for dyn Error {}
71+
6472
impl Error for core::convert::Infallible {
6573
fn kind(&self) -> ErrorKind {
6674
match *self {}

embedded-hal-bus/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
- Added the `alloc` feature.
1111
- Added a new `RcDevice` for I2C and SPI, a reference-counting equivalent to `RefCellDevice`.
12+
- Migrated `std` feature-gated `std::error::Error` implementations to `core::error::Error`
13+
- Increased MSRV to 1.81 due to `core::error::Error`
1214

1315
## [v0.2.0] - 2024-04-23
1416

embedded-hal-bus/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repository = "https://github.com/rust-embedded/embedded-hal"
1515
version = "0.2.0"
1616

1717
[features]
18-
# Enable shared bus implementations using `std::sync::Mutex`, and implement `std::error::Error` for `DeviceError`
18+
# Enable shared bus implementations using `std::sync::Mutex`
1919
std = ["alloc"]
2020
# Use `portable-atomic` to enable `atomic-device` on devices without native atomic CAS
2121
#

embedded-hal-bus/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ provides mechanisms to obtain multiple `I2c` instances out of a single `I2c` ins
3939
that does not natively support atomic CAS. If you enable this, you must also add `portable-atomic` to your crate with
4040
a feature flag such as `unsafe-assume-single-core` or `critical-section` to choose how atomic CAS is implemented.
4141
See <https://docs.rs/portable-atomic/1.7.0/portable_atomic/#optional-features> for more info.
42-
- **`std`**: enable shared bus implementations using `std::sync::Mutex`, and implement
43-
`std::error::Error` for `DeviceError`.
42+
- **`std`**: enable shared bus implementations using `std::sync::Mutex`.
4443

4544
## Minimum Supported Rust Version (MSRV)
4645

47-
This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
46+
This crate is guaranteed to compile on stable Rust 1.81 and up. It *might*
4847
compile with older versions but that may change in any new patch release.
4948

5049
See [here](../docs/msrv.md) for details on how the MSRV may be upgraded.

embedded-hal-bus/src/spi/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ impl<BUS: Display, CS: Display> Display for DeviceError<BUS, CS> {
4747
}
4848
}
4949

50-
#[cfg(feature = "std")]
51-
impl<BUS: Debug + Display, CS: Debug + Display> std::error::Error for DeviceError<BUS, CS> {}
50+
impl<BUS: Debug + Display, CS: Debug + Display> core::error::Error for DeviceError<BUS, CS> {}
5251

5352
impl<BUS, CS> Error for DeviceError<BUS, CS>
5453
where

0 commit comments

Comments
 (0)