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 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 @@ -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
Expand All @@ -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
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
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