Skip to content

Commit e82b4f3

Browse files
authored
Merge pull request #77 from vhdirk/defmt
Add optional defmt support for error types
2 parents 6b88a3c + 04abea2 commit e82b4f3

File tree

7 files changed

+20
-6
lines changed

7 files changed

+20
-6
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
include:
2323
# Test MSRV
24-
- rust: 1.56.0 # keep in sync with manifest rust-version
24+
- rust: 1.62.0 # keep in sync with manifest rust-version
2525
TARGET: x86_64-unknown-linux-gnu
2626

2727
# Test nightly but don't fail
@@ -45,4 +45,4 @@ jobs:
4545
if: ${{ contains(matrix.TARGET, 'x86_64') }}
4646
with:
4747
command: test
48-
args: --target=${{ matrix.TARGET }}
48+
args: --target=${{ matrix.TARGET }} --all-features

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Support for optional package `defmt` which allows for easy conversion for
13+
error types when using tools like `probe-rs` for logging over debuggers.
14+
1015
## [v0.5.1] - 2023-07-26
1116

1217
### Added

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ categories = ["no-std"]
44
description = "serde-json for no_std programs"
55
documentation = "https://docs.rs/serde-json-core"
66
edition = "2018"
7-
rust-version = "1.56.0" # keep in sync with ci, src/lib.rs, and README
7+
rust-version = "1.62.0" # keep in sync with ci, src/lib.rs, and README
88
keywords = ["serde", "json"]
99
license = "MIT OR Apache-2.0"
1010
name = "serde-json-core"
@@ -23,6 +23,11 @@ optional = true
2323
default-features = false
2424
version = "1.0.100"
2525

26+
[dependencies.defmt]
27+
version = "0.3.5"
28+
default-features = false
29+
optional = true
30+
2631
[dev-dependencies]
2732
serde_derive = "1.0.100"
2833

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This project is developed and maintained by the [rust-embedded-community].
1212

1313
## Minimum Supported Rust Version (MSRV)
1414

15-
This crate is guaranteed to compile on stable Rust 1.56.0 and up. It *might*
15+
This crate is guaranteed to compile on stable Rust 1.62.0 and up. It *might*
1616
compile with older versions but that may change in any new patch release.
1717

1818
## License

src/de/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub type Result<T> = core::result::Result<T, Error>;
1919
/// This type represents all possible errors that can occur when deserializing JSON data
2020
#[derive(Debug, PartialEq, Eq, Clone)]
2121
#[cfg_attr(not(feature = "custom-error-messages"), derive(Copy))]
22+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
2223
#[non_exhaustive]
2324
pub enum Error {
2425
/// EOF while parsing a list.
@@ -74,7 +75,9 @@ pub enum Error {
7475

7576
/// Error with a custom message that was preserved.
7677
#[cfg(feature = "custom-error-messages")]
77-
CustomErrorWithMessage(heapless::String<64>),
78+
CustomErrorWithMessage(
79+
#[cfg_attr(feature = "defmt", defmt(Debug2Format))] heapless::String<64>,
80+
),
7881
}
7982

8083
impl serde::de::StdError for Error {}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
//!
5353
//! # Minimum Supported Rust Version (MSRV)
5454
//!
55-
//! This crate is guaranteed to compile on stable Rust 1.56.0 and up. It *might* compile with older
55+
//! This crate is guaranteed to compile on stable Rust 1.62.0 and up. It *might* compile with older
5656
//! versions but that may change in any new patch release.
5757
5858
#![deny(missing_docs)]

src/ser/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub type Result<T> = ::core::result::Result<T, Error>;
2222

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

0 commit comments

Comments
 (0)