Skip to content

Commit d6c4a9c

Browse files
committed
Add defmt::Format bound to error types
1 parent b8fd20d commit d6c4a9c

7 files changed

Lines changed: 31 additions & 3 deletions

File tree

embedded-can/src/blocking.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ pub trait Can {
66
type Frame: crate::Frame;
77

88
/// Associated error type.
9+
#[cfg(feature = "defmt")]
10+
type Error: crate::Error + defmt::Format;
11+
/// Associated error type.
12+
#[cfg(not(feature = "defmt"))]
913
type Error: crate::Error;
1014

1115
/// Puts a frame in the transmit buffer. Blocks until space is available in

embedded-can/src/nb.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ pub trait Can {
66
type Frame: crate::Frame;
77

88
/// Associated error type.
9+
#[cfg(feature = "defmt")]
10+
type Error: crate::Error + defmt::Format;
11+
/// Associated error type.
12+
#[cfg(not(feature = "defmt"))]
913
type Error: crate::Error;
1014

1115
/// Puts a frame in the transmit buffer to be sent on the bus.

embedded-hal/src/digital.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ impl core::fmt::Display for ErrorKind {
5959
///
6060
/// This just defines the error type, to be used by the other traits.
6161
pub trait ErrorType {
62-
/// Error type
62+
/// Error type.
63+
#[cfg(feature = "defmt-03")]
64+
type Error: Error + defmt::Format;
65+
/// Error type.
66+
#[cfg(not(feature = "defmt-03"))]
6367
type Error: Error;
6468
}
6569

embedded-hal/src/i2c.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ impl core::fmt::Display for NoAcknowledgeSource {
265265
///
266266
/// This just defines the error type, to be used by the other traits.
267267
pub trait ErrorType {
268-
/// Error type
268+
/// Error type.
269+
#[cfg(feature = "defmt-03")]
270+
type Error: Error + defmt::Format;
271+
/// Error type.
272+
#[cfg(not(feature = "defmt-03"))]
269273
type Error: Error;
270274
}
271275

embedded-hal/src/pwm.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ impl core::fmt::Display for ErrorKind {
5858
///
5959
/// This just defines the error type, to be used by the other traits.
6060
pub trait ErrorType {
61-
/// Error type
61+
/// Error type.
62+
#[cfg(feature = "defmt-03")]
63+
type Error: Error + defmt::Format;
64+
/// Error type.
65+
#[cfg(not(feature = "defmt-03"))]
6266
type Error: Error;
6367
}
6468

embedded-hal/src/spi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ impl core::fmt::Display for ErrorKind {
307307
/// This just defines the error type, to be used by the other SPI traits.
308308
pub trait ErrorType {
309309
/// Error type.
310+
#[cfg(feature = "defmt-03")]
311+
type Error: Error + defmt::Format;
312+
/// Error type.
313+
#[cfg(not(feature = "defmt-03"))]
310314
type Error: Error;
311315
}
312316

embedded-io/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ impl Error for std::io::Error {
218218
/// which might be different types.
219219
pub trait ErrorType {
220220
/// Error type of all the IO operations on this type.
221+
#[cfg(feature = "defmt")]
222+
type Error: Error + defmt::Format;
223+
/// Error type of all the IO operations on this type.
224+
#[cfg(not(feature = "defmt"))]
221225
type Error: Error;
222226
}
223227

0 commit comments

Comments
 (0)