From d6d1d9be183a5dbd9cf4c5a07799fe4647a20e11 Mon Sep 17 00:00:00 2001 From: dimi Date: Wed, 17 Apr 2024 13:31:26 +0200 Subject: [PATCH] derive Serialize for de::Error and ser::Error --- Cargo.toml | 2 ++ src/de/mod.rs | 3 ++- src/ser/mod.rs | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a17db23f..5d924c1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,10 +17,12 @@ ryu = "1.0.5" [dependencies.heapless] version = "0.8" +features = ["serde"] optional = true [dependencies.serde] default-features = false +features = ["derive"] version = "1.0.100" [dependencies.defmt] diff --git a/src/de/mod.rs b/src/de/mod.rs index b44ddb79..d1c5048a 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -4,6 +4,7 @@ use core::str::FromStr; use core::{fmt, str}; use serde::de::{self, Visitor}; +use serde::Serialize; use self::enum_::{UnitVariantAccess, VariantAccess}; use self::map::MapAccess; @@ -17,7 +18,7 @@ mod seq; pub type Result = core::result::Result; /// This type represents all possible errors that can occur when deserializing JSON data -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize)] #[cfg_attr(not(feature = "custom-error-messages"), derive(Copy))] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] diff --git a/src/ser/mod.rs b/src/ser/mod.rs index cbec8a10..aafeb0f0 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -4,6 +4,7 @@ use core::mem::MaybeUninit; use core::{fmt, str}; use serde::ser; +use serde::Serialize; use serde::ser::SerializeStruct as _; #[cfg(feature = "heapless")] @@ -21,7 +22,7 @@ mod struct_; 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)] +#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] pub enum Error {