From 18a933091e231cb71b5eb7e1c16f366b9d37af86 Mon Sep 17 00:00:00 2001 From: 4t145 Date: Wed, 25 Oct 2023 15:07:42 +0800 Subject: [PATCH 1/3] recover `struct Void` to `struct Void {}` --- tardis/src/basic/tracing.rs | 4 ++-- tardis/src/web/web_resp.rs | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tardis/src/basic/tracing.rs b/tardis/src/basic/tracing.rs index a6e7c07a..0fb3e62f 100644 --- a/tardis/src/basic/tracing.rs +++ b/tardis/src/basic/tracing.rs @@ -3,10 +3,10 @@ use std::sync::Once; use crate::basic::result::TardisResult; use crate::config::config_dto::LogConfig; -use crate::TARDIS_INST; - #[allow(unused_imports)] use crate::consts::*; +use crate::TARDIS_INST; +pub use tracing_subscriber::filter::Directive; use tracing_subscriber::layer::Layered; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::EnvFilter; diff --git a/tardis/src/web/web_resp.rs b/tardis/src/web/web_resp.rs index 484baf49..42b6fe62 100644 --- a/tardis/src/web/web_resp.rs +++ b/tardis/src/web/web_resp.rs @@ -131,5 +131,16 @@ where pub records: Vec, } -#[derive(Object, Deserialize, Serialize, Clone, Debug, Default, Copy)] -pub struct Void; +#[derive(Object, Serialize, Clone, Debug, Default, Copy)] +/// This `Void` is for represent an empty object `{}` +/// Any value can be deserialized as `Void` +pub struct Void {} +pub const VOID: Void = Void {}; +impl<'de> Deserialize<'de> for Void { + fn deserialize(_: D) -> Result + where + D: serde::Deserializer<'de>, + { + Ok(Void {}) + } +} From 05feefc8f3abf637424fa2343a7565db0dfdfbdf Mon Sep 17 00:00:00 2001 From: 4t145 Date: Wed, 25 Oct 2023 16:19:28 +0800 Subject: [PATCH 2/3] ignore the value that will be deserialized into void --- tardis/src/web/web_resp.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tardis/src/web/web_resp.rs b/tardis/src/web/web_resp.rs index 42b6fe62..57b6ef60 100644 --- a/tardis/src/web/web_resp.rs +++ b/tardis/src/web/web_resp.rs @@ -132,15 +132,17 @@ where } #[derive(Object, Serialize, Clone, Debug, Default, Copy)] -/// This `Void` is for represent an empty object `{}` -/// Any value can be deserialized as `Void` -pub struct Void {} -pub const VOID: Void = Void {}; +/// This `Void` is for represent an empty value. +/// Any value can be deserialized as `Void`. +/// Void will be serialized as json's `null`. +pub struct Void; impl<'de> Deserialize<'de> for Void { - fn deserialize(_: D) -> Result + fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { - Ok(Void {}) + // ignore this value whatever + let _ = deserializer.deserialize_any(serde::de::IgnoredAny)?; + Ok(Void) } -} +} \ No newline at end of file From fc2949f854271b1f20ae5a75d6e20485859fa7f5 Mon Sep 17 00:00:00 2001 From: 4t145 Date: Wed, 25 Oct 2023 16:34:07 +0800 Subject: [PATCH 3/3] cargo fmt --- tardis/src/web/web_resp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tardis/src/web/web_resp.rs b/tardis/src/web/web_resp.rs index 57b6ef60..11782492 100644 --- a/tardis/src/web/web_resp.rs +++ b/tardis/src/web/web_resp.rs @@ -145,4 +145,4 @@ impl<'de> Deserialize<'de> for Void { let _ = deserializer.deserialize_any(serde::de::IgnoredAny)?; Ok(Void) } -} \ No newline at end of file +}