Skip to content

Commit

Permalink
Implement defmt::Format for Error
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed Oct 24, 2022
1 parent a1c7b99 commit b8cc67f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ documentation = "https://docs.rs/esp-at-nal"
[dependencies]
atat = "0.17.0"
embedded-nal = "0.6.0"
defmt = { version = "0.3", optional = true }
nb = "1.0.0"
fugit = "0.3.6"
fugit-timer = "0.1.3"
Expand All @@ -27,6 +28,7 @@ mockall = "0.11.2"

[features]
default = ["examples"]
defmt = ["dep:defmt", "atat/defmt"]

# Fail on warnings
strict = []
Expand Down
24 changes: 24 additions & 0 deletions src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,30 @@ pub enum Error {
TimerError,
}

#[cfg(feature = "defmt")]
impl defmt::Format for Error {
fn format(&self, f: defmt::Formatter) {
match self {
Error::EnablingMultiConnectionsFailed(e) => defmt::write!(f, "Error::EnablingMultiConnectionsFailed({})", e),
Error::EnablingPassiveSocketModeFailed(e) => defmt::write!(f, "Error::EnablingPassiveSocketModeFailed({})", e),
Error::ConnectError(e) => defmt::write!(f, "Error::ConnectError({})", e),
Error::TransmissionStartFailed(e) => defmt::write!(f, "Error::TransmissionStartFailed({})", e),
Error::SendFailed(e) => defmt::write!(f, "Error::SendFailed({})", e),
Error::ReceiveFailed(e) => defmt::write!(f, "Error::ReceiveFailed({})", e),
Error::CloseError(e) => defmt::write!(f, "Error::CloseError({})", e),
Error::PartialSend => defmt::write!(f, "Error::PartialSend"),
Error::UnconfirmedSocketState => defmt::write!(f, "Error::UnconfirmedSocketState"),
Error::NoSocketAvailable => defmt::write!(f, "Error::NoSocketAvailable"),
Error::AlreadyConnected => defmt::write!(f, "Error::AlreadyConnected"),
Error::SocketUnconnected => defmt::write!(f, "Error::SocketUnconnected"),
Error::ClosingSocket => defmt::write!(f, "Error::ClosingSocket"),
Error::ReceiveOverflow => defmt::write!(f, "Error::ReceiveOverflow"),
Error::UnexpectedWouldBlock => defmt::write!(f, "Error::UnexpectedWouldBlock"),
Error::TimerError => defmt::write!(f, "Error::TimerError"),
}
}
}

impl<A: AtatClient, T: Timer<TIMER_HZ>, const TIMER_HZ: u32, const TX_SIZE: usize, const RX_SIZE: usize> TcpClientStack
for Adapter<A, T, TIMER_HZ, TX_SIZE, RX_SIZE>
{
Expand Down

0 comments on commit b8cc67f

Please sign in to comment.