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 #76

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: build
args: --target=${{ matrix.TARGET }}
args: --target=${{ matrix.TARGET }} --all-features
- uses: actions-rs/cargo@v1
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.0"
default-features = false
optional = true

[dev-dependencies]
serde_derive = "1.0.100"

Expand Down
1 change: 1 addition & 0 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/// 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))]

Check failure on line 22 in src/de/mod.rs

View workflow job for this annotation

GitHub Actions / ci-linux (nightly, x86_64-unknown-linux-gnu, true)

the trait bound `heapless::String<64>: Format` is not satisfied

Check failure on line 22 in src/de/mod.rs

View workflow job for this annotation

GitHub Actions / ci-linux (stable, x86_64-unknown-linux-gnu)

the trait bound `heapless::String<64>: Format` is not satisfied
Copy link
Member

@ryan-summers ryan-summers Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to add:

        #[cfg_attr(feature = "defmt", defmt(defmt::Debug2Format))]

above the heapless::String<64> error type.

Copy link
Contributor

@Georges760 Georges760 Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or adding "defmt-impl" feature into the heapless dependency

#[non_exhaustive]
pub enum Error {
/// EOF while parsing a list.
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