Merge pull request #369 from derekdreery/defmt_mpsc

Add defmt support for mpsc errors.
This commit is contained in:
Dario Nieuwenhuis 2021-08-22 01:17:11 +02:00 committed by GitHub
commit fde24dba3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -386,6 +386,7 @@ where
///
/// [`try_recv`]: super::Receiver::try_recv
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum TryRecvError {
/// A message could not be received because the channel is empty.
Empty,
@ -404,6 +405,13 @@ impl<T> fmt::Display for SendError<T> {
}
}
#[cfg(feature = "defmt")]
impl<T> defmt::Format for SendError<T> {
fn format(&self, fmt: defmt::Formatter<'_>) {
defmt::write!(fmt, "channel closed")
}
}
/// This enumeration is the list of the possible error outcomes for the
/// [try_send](super::Sender::try_send) method.
#[derive(Debug)]
@ -430,6 +438,16 @@ impl<T> fmt::Display for TrySendError<T> {
}
}
#[cfg(feature = "defmt")]
impl<T> defmt::Format for TrySendError<T> {
fn format(&self, fmt: defmt::Formatter<'_>) {
match self {
TrySendError::Full(..) => defmt::write!(fmt, "no available capacity"),
TrySendError::Closed(..) => defmt::write!(fmt, "channel closed"),
}
}
}
struct ChannelState<T, const N: usize> {
buf: [MaybeUninit<UnsafeCell<T>>; N],
read_pos: usize,