Skip to content

Commit b574c55

Browse files
Merge #308
308: Require all associated error types to implement `core::fmt::Debug` r=eldruin a=GrantM11235 Co-authored-by: Grant Miller <[email protected]>
2 parents b8e3ec5 + a7639c2 commit b574c55

File tree

16 files changed

+37
-35
lines changed

16 files changed

+37
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2323
- Removed `prelude` to avoid method name conflicts between different flavors (blocking, nb) of the same trait. Traits must now be manually imported.
2424
- Removed the various `Default` marker traits.
2525
- Removed `&[W]` returned slice in `spi::blocking::Transfer`.
26+
- Require all associated error types to implement `core::fmt::Debug`.
2627

2728
### Removed
2829
- Removed random number generation (`rng`) traits in favor of [rand_core](https://crates.io/crates/rand_core).

src/adc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub mod nb {
8484
/// ```
8585
pub trait OneShot<ADC, Word, Pin: Channel<ADC>> {
8686
/// Error type returned by ADC methods
87-
type Error;
87+
type Error: core::fmt::Debug;
8888

8989
/// Request that the ADC begin a conversion on the specified pin
9090
///

src/capture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub trait Capture {
5959
///
6060
/// - *overcapture*, the previous capture value was overwritten because it
6161
/// was not read in a timely manner
62-
type Error;
62+
type Error: core::fmt::Debug;
6363

6464
/// Enumeration of channels that can be used with this `Capture` interface
6565
///

src/delay.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub mod blocking {
1515
/// implement this trait for different types of `UXX`.
1616
pub trait DelayMs<UXX> {
1717
/// Enumeration of `DelayMs` errors
18-
type Error;
18+
type Error: core::fmt::Debug;
1919

2020
/// Pauses execution for `ms` milliseconds
2121
fn delay_ms(&mut self, ms: UXX) -> Result<(), Self::Error>;
@@ -27,7 +27,7 @@ pub mod blocking {
2727
/// implement this trait for different types of `UXX`.
2828
pub trait DelayUs<UXX> {
2929
/// Enumeration of `DelayMs` errors
30-
type Error;
30+
type Error: core::fmt::Debug;
3131

3232
/// Pauses execution for `us` microseconds
3333
fn delay_us(&mut self, us: UXX) -> Result<(), Self::Error>;

src/digital.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub mod blocking {
5151
/// Single digital push-pull output pin
5252
pub trait OutputPin {
5353
/// Error type
54-
type Error;
54+
type Error: core::fmt::Debug;
5555

5656
/// Drives the pin low
5757
///
@@ -98,7 +98,7 @@ pub mod blocking {
9898
/// implemented. Otherwise, implement this using hardware mechanisms.
9999
pub trait ToggleableOutputPin {
100100
/// Error type
101-
type Error;
101+
type Error: core::fmt::Debug;
102102

103103
/// Toggle pin output.
104104
fn toggle(&mut self) -> Result<(), Self::Error>;
@@ -107,7 +107,7 @@ pub mod blocking {
107107
/// Single digital input pin
108108
pub trait InputPin {
109109
/// Error type
110-
type Error;
110+
type Error: core::fmt::Debug;
111111

112112
/// Is the input pin high?
113113
fn is_high(&self) -> Result<bool, Self::Error>;
@@ -125,7 +125,7 @@ pub mod blocking {
125125
/// use core::time::Duration;
126126
/// use embedded_hal::digital::blocking::{IoPin, InputPin, OutputPin};
127127
///
128-
/// pub fn ping_and_read<TInputPin, TOutputPin, TError>(
128+
/// pub fn ping_and_read<TInputPin, TOutputPin, TError: core::fmt::Debug>(
129129
/// mut pin: TOutputPin, delay_fn: &dyn Fn(Duration) -> ()) -> Result<bool, TError>
130130
/// where
131131
/// TInputPin : InputPin<Error = TError> + IoPin<TInputPin, TOutputPin, Error = TError>,
@@ -148,7 +148,7 @@ pub mod blocking {
148148
TOutput: OutputPin + IoPin<TInput, TOutput>,
149149
{
150150
/// Error type.
151-
type Error;
151+
type Error: core::fmt::Debug;
152152

153153
/// Tries to convert this pin to input mode.
154154
///

src/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! TODO write example of usage
44
use core::fmt::{Result, Write};
55

6-
impl<Word, Error> Write for dyn crate::serial::nb::Write<Word, Error = Error> + '_
6+
impl<Word, Error: core::fmt::Debug> Write for dyn crate::serial::nb::Write<Word, Error = Error> + '_
77
where
88
Word: From<u8>,
99
{

src/i2c.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
//! i2c: I2C,
6464
//! }
6565
//!
66-
//! impl<I2C, E> TemperatureSensorDriver<I2C>
66+
//! impl<I2C, E: core::fmt::Debug> TemperatureSensorDriver<I2C>
6767
//! where
6868
//! I2C: WriteRead<Error = E>,
6969
//! {
@@ -86,7 +86,7 @@
8686
//! i2c: I2C,
8787
//! }
8888
//!
89-
//! impl<I2C, E> TemperatureSensorDriver<I2C>
89+
//! impl<I2C, E: core::fmt::Debug> TemperatureSensorDriver<I2C>
9090
//! where
9191
//! I2C: WriteRead<TenBitAddress, Error = E>,
9292
//! {
@@ -124,7 +124,7 @@ pub mod blocking {
124124
/// Blocking read
125125
pub trait Read<A: AddressMode = SevenBitAddress> {
126126
/// Error type
127-
type Error;
127+
type Error: core::fmt::Debug;
128128

129129
/// Reads enough bytes from slave with `address` to fill `buffer`
130130
///
@@ -150,7 +150,7 @@ pub mod blocking {
150150
/// Blocking write
151151
pub trait Write<A: AddressMode = SevenBitAddress> {
152152
/// Error type
153-
type Error;
153+
type Error: core::fmt::Debug;
154154

155155
/// Writes bytes to slave with address `address`
156156
///
@@ -174,7 +174,7 @@ pub mod blocking {
174174
/// Blocking write (iterator version)
175175
pub trait WriteIter<A: AddressMode = SevenBitAddress> {
176176
/// Error type
177-
type Error;
177+
type Error: core::fmt::Debug;
178178

179179
/// Writes bytes to slave with address `address`
180180
///
@@ -189,7 +189,7 @@ pub mod blocking {
189189
/// Blocking write + read
190190
pub trait WriteRead<A: AddressMode = SevenBitAddress> {
191191
/// Error type
192-
type Error;
192+
type Error: core::fmt::Debug;
193193

194194
/// Writes bytes to slave with address `address` and then reads enough bytes to fill `buffer` *in a
195195
/// single transaction*
@@ -224,7 +224,7 @@ pub mod blocking {
224224
/// Blocking write (iterator version) + read
225225
pub trait WriteIterRead<A: AddressMode = SevenBitAddress> {
226226
/// Error type
227-
type Error;
227+
type Error: core::fmt::Debug;
228228

229229
/// Writes bytes to slave with address `address` and then reads enough bytes to fill `buffer` *in a
230230
/// single transaction*
@@ -258,7 +258,7 @@ pub mod blocking {
258258
/// This allows combining operations within an I2C transaction.
259259
pub trait Transactional<A: AddressMode = SevenBitAddress> {
260260
/// Error type
261-
type Error;
261+
type Error: core::fmt::Debug;
262262

263263
/// Execute the provided operations on the I2C bus.
264264
///
@@ -285,7 +285,7 @@ pub mod blocking {
285285
/// This allows combining operation within an I2C transaction.
286286
pub trait TransactionalIter<A: AddressMode = SevenBitAddress> {
287287
/// Error type
288-
type Error;
288+
type Error: core::fmt::Debug;
289289

290290
/// Execute the provided operations on the I2C bus (iterator version).
291291
///

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
//! /// A serial interface
7878
//! pub trait Serial {
7979
//! /// Error type associated to this serial interface
80-
//! type Error;
80+
//! type Error: core::fmt::Debug;
8181
//!
8282
//! /// Reads a single byte
8383
//! fn read(&mut self) -> nb::Result<u8, Self::Error>;
@@ -144,6 +144,7 @@
144144
//! pub type Serial1 = Serial<USART1>;
145145
//!
146146
//! /// Serial interface error
147+
//! #[derive(Debug)]
147148
//! pub enum Error {
148149
//! /// Buffer overrun
149150
//! Overrun,

src/pwm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub mod blocking {
5454
// PWM channels. Here a certain number of channels are multiplexed in a single implementer.
5555
pub trait Pwm {
5656
/// Enumeration of `Pwm` errors
57-
type Error;
57+
type Error: core::fmt::Debug;
5858

5959
/// Enumeration of channels that can be used with this `Pwm` interface
6060
///
@@ -107,7 +107,7 @@ pub mod blocking {
107107
/// See `Pwm` for details
108108
pub trait PwmPin {
109109
/// Enumeration of `PwmPin` errors
110-
type Error;
110+
type Error: core::fmt::Debug;
111111

112112
/// Type for the `duty` methods
113113
///

src/qei.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub mod blocking {
7070
// reference implementation
7171
pub trait Qei {
7272
/// Enumeration of `Qei` errors
73-
type Error;
73+
type Error: core::fmt::Debug;
7474

7575
/// The type of the value returned by `count`
7676
type Count;

0 commit comments

Comments
 (0)