Skip to content

Commit d1fdfc8

Browse files
committed
Implement std::error::Error for ErrorKinds
1 parent 024631b commit d1fdfc8

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
# The default target we're compiling on and for
2020
TARGET: [x86_64-unknown-linux-gnu, thumbv6m-none-eabi, thumbv7m-none-eabi]
2121

22+
FEATURES: ["", "--features std"]
23+
2224
include:
2325
# Test MSRV
2426
- rust: 1.40.0
@@ -40,4 +42,4 @@ jobs:
4042
- uses: actions-rs/cargo@v1
4143
with:
4244
command: check
43-
args: --target=${{ matrix.TARGET }}
45+
args: --target=${{ matrix.TARGET }} ${{ matrix.FEATURES }}

.github/workflows/test.yml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
rust: [stable]
17+
FEATURES: ["", "--features std"]
1718

1819
include:
1920
- rust: 1.40.0
@@ -35,3 +36,4 @@ jobs:
3536
- uses: actions-rs/cargo@v1
3637
with:
3738
command: test
39+
args: ${{ matrix.FEATURES }}

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ nb = "1"
2121
[dev-dependencies.stm32f1]
2222
version = "0.12"
2323
features = ["stm32f103", "rt"]
24+
25+
[features]
26+
std = []

src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ pub mod i2c {
5858
}
5959
}
6060
}
61+
62+
#[cfg(feature = "std")]
63+
impl std::error::Error for ErrorKind {}
6164
}
6265

6366
pub mod spi {
@@ -120,6 +123,9 @@ pub mod spi {
120123
}
121124
}
122125
}
126+
127+
#[cfg(feature = "std")]
128+
impl std::error::Error for ErrorKind {}
123129
}
124130

125131
pub mod serial {
@@ -177,4 +183,7 @@ pub mod serial {
177183
}
178184
}
179185
}
186+
187+
#[cfg(feature = "std")]
188+
impl std::error::Error for ErrorKind {}
180189
}

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@
413413
414414
#![doc(html_root_url = "https://docs.rs/embedded-hal/1.0.0-alpha.4")]
415415
#![deny(missing_docs)]
416-
#![no_std]
416+
#![cfg_attr(not(feature = "std"), no_std)]
417417

418418
pub mod blocking;
419419
mod errors;

0 commit comments

Comments
 (0)