diff options
| author | Richard Dodd <[email protected]> | 2021-08-21 22:36:23 +0100 |
|---|---|---|
| committer | Richard Dodd <[email protected]> | 2021-08-21 22:36:23 +0100 |
| commit | 170121cdf6fb1b677be676ee24643437ecfb064f (patch) | |
| tree | c5aac616944e58a48c597221b250ba2ddb6ff01a | |
| parent | 1e1cd0506aa655456d7cbf7d6915b46abf7829e5 (diff) | |
Add defmt support for mpsc errors.
| -rw-r--r-- | embassy/src/util/mpsc.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/embassy/src/util/mpsc.rs b/embassy/src/util/mpsc.rs index bad1058a3..b9a95d6a3 100644 --- a/embassy/src/util/mpsc.rs +++ b/embassy/src/util/mpsc.rs | |||
| @@ -386,6 +386,7 @@ where | |||
| 386 | /// | 386 | /// |
| 387 | /// [`try_recv`]: super::Receiver::try_recv | 387 | /// [`try_recv`]: super::Receiver::try_recv |
| 388 | #[derive(PartialEq, Eq, Clone, Copy, Debug)] | 388 | #[derive(PartialEq, Eq, Clone, Copy, Debug)] |
| 389 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 389 | pub enum TryRecvError { | 390 | pub enum TryRecvError { |
| 390 | /// A message could not be received because the channel is empty. | 391 | /// A message could not be received because the channel is empty. |
| 391 | Empty, | 392 | Empty, |
| @@ -404,6 +405,14 @@ impl<T> fmt::Display for SendError<T> { | |||
| 404 | } | 405 | } |
| 405 | } | 406 | } |
| 406 | 407 | ||
| 408 | #[cfg(feature = "defmt")] | ||
| 409 | impl<T> defmt::Format for SendError<T> { | ||
| 410 | fn format(&self, fmt: defmt::Formatter<'_>) { | ||
| 411 | defmt::write!(fmt, "channel closed") | ||
| 412 | } | ||
| 413 | } | ||
| 414 | |||
| 415 | |||
| 407 | /// This enumeration is the list of the possible error outcomes for the | 416 | /// This enumeration is the list of the possible error outcomes for the |
| 408 | /// [try_send](super::Sender::try_send) method. | 417 | /// [try_send](super::Sender::try_send) method. |
| 409 | #[derive(Debug)] | 418 | #[derive(Debug)] |
| @@ -430,6 +439,20 @@ impl<T> fmt::Display for TrySendError<T> { | |||
| 430 | } | 439 | } |
| 431 | } | 440 | } |
| 432 | 441 | ||
| 442 | #[cfg(feature = "defmt")] | ||
| 443 | impl<T> defmt::Format for TrySendError<T> { | ||
| 444 | fn format(&self, fmt: defmt::Formatter<'_>) { | ||
| 445 | defmt::write!( | ||
| 446 | fmt, | ||
| 447 | "{}", | ||
| 448 | match self { | ||
| 449 | TrySendError::Full(..) => "no available capacity", | ||
| 450 | TrySendError::Closed(..) => "channel closed", | ||
| 451 | } | ||
| 452 | ) | ||
| 453 | } | ||
| 454 | } | ||
| 455 | |||
| 433 | struct ChannelState<T, const N: usize> { | 456 | struct ChannelState<T, const N: usize> { |
| 434 | buf: [MaybeUninit<UnsafeCell<T>>; N], | 457 | buf: [MaybeUninit<UnsafeCell<T>>; N], |
| 435 | read_pos: usize, | 458 | read_pos: usize, |
