Skip to content

Commit

Permalink
implement defmt::format
Browse files Browse the repository at this point in the history
  • Loading branch information
tarfu committed Oct 9, 2023
1 parent 89ac28f commit cd491fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ublox-cellular/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ pub enum Error {
_Unknown,
}

#[cfg(feature = "defmt")]
impl defmt::Format for Error {
fn format(&self, f: defmt::Formatter<'_>) {
match self {
Self::BaudDetection => defmt::write!(f, "BaudDetection"),
Self::Busy => defmt::write!(f, "Busy"),
Self::Uninitialized => defmt::write!(f, "Uninitialized"),
Self::StateTimeout => defmt::write!(f, "StateTimeout"),
Self::Network(e) => defmt::write!(f, "Network({:?})", e),
Self::DataService(e) => defmt::write!(f, "DataService({:?})", e),
Self::Generic(e) => defmt::write!(f, "Generic({:?})", e),
Self::_Unknown => defmt::write!(f, "_Unknown"),
_ => defmt::write!(f, "non_exhaustive"),
}
}
}

impl From<DataServiceError> for Error {
fn from(e: DataServiceError) -> Self {
// Unwrap generic and network errors
Expand Down
1 change: 1 addition & 0 deletions ublox-cellular/src/services/data/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::network::Error as NetworkError;
use ublox_sockets::Error as SocketError;

#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
InvalidApn,
SocketMemory,
Expand Down

0 comments on commit cd491fe

Please sign in to comment.