-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement defmt::Format for Error #11
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,34 @@ pub enum Error { | |
TimerError, | ||
} | ||
|
||
#[cfg(feature = "defmt")] | ||
impl defmt::Format for Error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any reasons against the use of derive?
However, I have to admit that I have not looked at the output of cargo expand and of course there could be good reasons for a manual implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I simply wasn't aware that a derive macro exists for defmt 🙂 I'll test the output differences in my project sometime. (I haven't figured out how to convert defmt writes to a string on regular std-Rust on Linux...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems this is not possible currently: knurling-rs/defmt#463 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you had a chance to test the derive? If not, I'm also fine with the current implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, not yet. I'll try to take a look again soon. |
||
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> | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first intuition would have been to implement the features as a matrix axis. But that would have made too much overhead, and so it is nice and lean. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think a matrix makes sense if we have even more distinct features, but for now this is probably the simplest and fastest way (because build cache is shared).