From 9295f5cd92565f754a57a5e80d11decaf1b725f0 Mon Sep 17 00:00:00 2001 From: Alec Cox Date: Thu, 21 Sep 2023 18:50:28 -0700 Subject: [PATCH 1/5] add optional defmt support for error types add defmt as an optional dependent package --- Cargo.toml | 5 +++++ src/de/mod.rs | 1 + src/ser/mod.rs | 1 + 3 files changed, 7 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 71fd9b5a..d8d1d23f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/de/mod.rs b/src/de/mod.rs index dcfd9bd9..c04d7379 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -19,6 +19,7 @@ pub type Result = core::result::Result; /// 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. diff --git a/src/ser/mod.rs b/src/ser/mod.rs index 75153e8d..ede8b624 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -22,6 +22,7 @@ pub type Result = ::core::result::Result; /// 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 From 3a425f8d28427f9ba26ba3bbba361bd8e28bf018 Mon Sep 17 00:00:00 2001 From: Alec Cox Date: Sat, 23 Sep 2023 11:48:28 -0700 Subject: [PATCH 2/5] defmt changelog and all-feature CI --- .github/workflows/ci.yml | 4 ++-- CHANGELOG.md | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2a78cd1..70629eae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d3fca4b..6bd1ee2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 1a97e93d401f9c5232e4dd752f5a416e02341e3b Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Sat, 4 Nov 2023 17:04:24 +0100 Subject: [PATCH 3/5] annotate String<64> --- Cargo.toml | 2 +- src/de/mod.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d8d1d23f..c8afd181 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ default-features = false version = "1.0.100" [dependencies.defmt] -version = "0.3.0" +version = "0.3.5" default-features = false optional = true diff --git a/src/de/mod.rs b/src/de/mod.rs index c04d7379..613323bc 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -75,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 {} From 76853043129b3f0d756d74c94fc100f1be69af95 Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Tue, 7 Nov 2023 09:02:51 +0100 Subject: [PATCH 4/5] Update .github/workflows/ci.yml Co-authored-by: Diego Barrios Romero --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70629eae..7f7d3a46 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: build - args: --target=${{ matrix.TARGET }} --all-features + args: --target=${{ matrix.TARGET }} - uses: actions-rs/cargo@v1 if: ${{ contains(matrix.TARGET, 'x86_64') }} with: From 04abea2030db260a317aa635464c77ff17a59d4f Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Tue, 7 Nov 2023 11:18:57 +0100 Subject: [PATCH 5/5] bump MSRV --- .github/workflows/ci.yml | 2 +- Cargo.toml | 2 +- README.md | 2 +- src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f7d3a46..6ee57d56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: include: # Test MSRV - - rust: 1.56.0 # keep in sync with manifest rust-version + - rust: 1.62.0 # keep in sync with manifest rust-version TARGET: x86_64-unknown-linux-gnu # Test nightly but don't fail diff --git a/Cargo.toml b/Cargo.toml index c8afd181..f580ce7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ categories = ["no-std"] description = "serde-json for no_std programs" documentation = "https://docs.rs/serde-json-core" edition = "2018" -rust-version = "1.56.0" # keep in sync with ci, src/lib.rs, and README +rust-version = "1.62.0" # keep in sync with ci, src/lib.rs, and README keywords = ["serde", "json"] license = "MIT OR Apache-2.0" name = "serde-json-core" diff --git a/README.md b/README.md index 07a00f80..e63ad91c 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This project is developed and maintained by the [rust-embedded-community]. ## Minimum Supported Rust Version (MSRV) -This crate is guaranteed to compile on stable Rust 1.56.0 and up. It *might* +This crate is guaranteed to compile on stable Rust 1.62.0 and up. It *might* compile with older versions but that may change in any new patch release. ## License diff --git a/src/lib.rs b/src/lib.rs index 3ac15832..7f2de3a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,7 +52,7 @@ //! //! # Minimum Supported Rust Version (MSRV) //! -//! This crate is guaranteed to compile on stable Rust 1.56.0 and up. It *might* compile with older +//! This crate is guaranteed to compile on stable Rust 1.62.0 and up. It *might* compile with older //! versions but that may change in any new patch release. #![deny(missing_docs)]