Skip to content
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

Add optional defmt support for error types #77

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
if: ${{ contains(matrix.TARGET, 'x86_64') }}
with:
command: test
args: --target=${{ matrix.TARGET }}
args: --target=${{ matrix.TARGET }} --all-features
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- Support for optional package `defmt` which allows for easy conversion for
error types when using tools like `probe-rs` for logging over debuggers.

## [v0.5.1] - 2023-07-26

### Added
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ optional = true
default-features = false
version = "1.0.100"

[dependencies.defmt]
version = "0.3.5"
default-features = false
optional = true

[dev-dependencies]
serde_derive = "1.0.100"

Expand Down
5 changes: 4 additions & 1 deletion src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub type Result<T> = core::result::Result<T, Error>;
/// This type represents all possible errors that can occur when deserializing JSON data
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(not(feature = "custom-error-messages"), derive(Copy))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum Error {
/// EOF while parsing a list.
Expand Down Expand Up @@ -74,7 +75,9 @@ pub enum Error {

/// Error with a custom message that was preserved.
#[cfg(feature = "custom-error-messages")]
CustomErrorWithMessage(heapless::String<64>),
CustomErrorWithMessage(
#[cfg_attr(feature = "defmt", defmt(Debug2Format))] heapless::String<64>,
),
}

impl serde::de::StdError for Error {}
Expand Down
1 change: 1 addition & 0 deletions src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub type Result<T> = ::core::result::Result<T, Error>;

/// This type represents all possible errors that can occur when serializing JSON data
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum Error {
/// Buffer is full
Expand Down
Loading