From da733b4711cef398a26b62266a8021a347376ff2 Mon Sep 17 00:00:00 2001 From: Coffee Date: Fri, 27 Mar 2026 15:28:41 +0800 Subject: [PATCH] Remove redundant serde defaults from optional fields --- channels-src/wechat/src/types.rs | 39 ----------------------- src/channels/wasm/attachment_hydration.rs | 1 - src/extensions/mod.rs | 21 ++++-------- src/extensions/wechat_login.rs | 3 -- 4 files changed, 7 insertions(+), 57 deletions(-) diff --git a/channels-src/wechat/src/types.rs b/channels-src/wechat/src/types.rs index 362a2097..675425c1 100644 --- a/channels-src/wechat/src/types.rs +++ b/channels-src/wechat/src/types.rs @@ -80,23 +80,17 @@ pub struct GetConfigRequest { #[derive(Debug, Clone, Deserialize)] pub struct GetUpdatesResponse { - #[serde(default)] pub ret: Option, - #[serde(default)] pub errcode: Option, - #[serde(default)] pub errmsg: Option, #[serde(default)] pub msgs: Vec, - #[serde(default)] pub get_updates_buf: Option, } #[derive(Debug, Clone, Deserialize)] pub struct GetUploadUrlResponse { - #[serde(default)] pub upload_param: Option, - #[serde(default)] pub thumb_upload_param: Option, } @@ -128,17 +122,11 @@ pub struct OutboundWechatMessage { #[derive(Debug, Clone, Deserialize)] pub struct WechatMessage { - #[serde(default)] pub message_id: Option, - #[serde(default)] pub from_user_id: Option, - #[serde(default)] pub to_user_id: Option, - #[serde(default)] pub session_id: Option, - #[serde(default)] pub message_type: Option, - #[serde(default)] pub context_token: Option, #[serde(default)] pub item_list: Vec, @@ -146,33 +134,23 @@ pub struct WechatMessage { #[derive(Debug, Clone, Deserialize)] pub struct GetConfigResponse { - #[serde(default)] pub ret: Option, - #[serde(default)] pub errmsg: Option, - #[serde(default)] pub typing_ticket: Option, } #[derive(Debug, Clone, Deserialize)] pub struct SendTypingResponse { - #[serde(default)] pub ret: Option, - #[serde(default)] pub errmsg: Option, } #[derive(Debug, Clone, Deserialize, Serialize)] pub struct MessageItem { - #[serde(default)] pub r#type: Option, - #[serde(default)] pub text_item: Option, - #[serde(default)] pub image_item: Option, - #[serde(default)] pub voice_item: Option, - #[serde(default)] pub file_item: Option, } @@ -183,56 +161,39 @@ pub struct TextItem { #[derive(Debug, Clone, Deserialize, Serialize)] pub struct CdnMedia { - #[serde(default)] pub encrypt_query_param: Option, - #[serde(default)] pub aes_key: Option, - #[serde(default)] pub encrypt_type: Option, } #[derive(Debug, Clone, Deserialize, Serialize)] pub struct ImageItem { - #[serde(default)] pub media: Option, - #[serde(default)] pub aeskey: Option, - #[serde(default)] pub mid_size: Option, } #[derive(Debug, Clone, Deserialize, Serialize)] pub struct VoiceItem { - #[serde(default)] pub media: Option, - #[serde(default)] pub encode_type: Option, - #[serde(default)] pub playtime: Option, - #[serde(default)] pub text: Option, } #[derive(Debug, Clone, Deserialize, Serialize)] pub struct FileItem { - #[serde(default)] pub media: Option, - #[serde(default)] pub file_name: Option, - #[serde(default)] pub len: Option, } #[derive(Debug, Clone, Deserialize, Serialize)] pub struct OutboundMetadata { pub from_user_id: String, - #[serde(default)] pub to_user_id: Option, - #[serde(default)] pub message_id: Option, - #[serde(default)] pub session_id: Option, - #[serde(default)] pub context_token: Option, } diff --git a/src/channels/wasm/attachment_hydration.rs b/src/channels/wasm/attachment_hydration.rs index db079cdd..b722ffc4 100644 --- a/src/channels/wasm/attachment_hydration.rs +++ b/src/channels/wasm/attachment_hydration.rs @@ -16,7 +16,6 @@ const WECHAT_SILK_SAMPLE_RATE_HZ: i32 = 24_000; #[derive(Debug, Deserialize)] struct WechatAttachmentExtras { - #[serde(default)] wechat_aes_key: Option, } diff --git a/src/extensions/mod.rs b/src/extensions/mod.rs index 21566574..881f34df 100644 --- a/src/extensions/mod.rs +++ b/src/extensions/mod.rs @@ -70,12 +70,12 @@ pub struct RegistryEntry { /// Where to get this extension. pub source: ExtensionSource, /// Fallback source when the primary source fails (e.g., download 404 → build from source). - #[serde(default, skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub fallback_source: Option>, /// How authentication works. pub auth_hint: AuthHint, /// Extension version (semver), if known. - #[serde(default, skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub version: Option, } @@ -88,17 +88,14 @@ pub enum ExtensionSource { /// Downloadable WASM binary. WasmDownload { wasm_url: String, - #[serde(default)] capabilities_url: Option, }, /// Build from local source directory. WasmBuildable { #[serde(alias = "repo_url")] source_dir: String, - #[serde(default)] build_dir: Option, /// Crate name used to locate the build artifact binary. - #[serde(default)] crate_name: Option, }, /// Discovered online (not yet validated for a specific source type). @@ -390,13 +387,9 @@ impl<'de> Deserialize<'de> for AuthResult { struct Raw { name: String, kind: ExtensionKind, - #[serde(default)] auth_url: Option, - #[serde(default)] callback_type: Option, - #[serde(default)] instructions: Option, - #[serde(default)] setup_url: Option, #[serde(default)] awaiting_token: bool, @@ -448,7 +441,7 @@ pub struct InteractiveLoginInfo { /// User-facing button label. pub button_label: String, /// Optional short instructions shown above the login control. - #[serde(default, skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub instructions: Option, } @@ -462,10 +455,10 @@ pub struct InteractiveLoginStartResult { /// Human-readable message for the UI. pub message: String, /// Optional QR/image URL for browser display. - #[serde(default, skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub qr_code_url: Option, /// Optional short instructions shown alongside the QR code. - #[serde(default, skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub instructions: Option, } @@ -479,10 +472,10 @@ pub struct InteractiveLoginPollResult { /// Human-readable message for the UI. pub message: String, /// Optional refreshed QR/image URL. - #[serde(default, skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub qr_code_url: Option, /// Whether the extension was successfully activated as part of login completion. - #[serde(default, skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub activated: Option, } diff --git a/src/extensions/wechat_login.rs b/src/extensions/wechat_login.rs index 66f7317b..1803925c 100644 --- a/src/extensions/wechat_login.rs +++ b/src/extensions/wechat_login.rs @@ -57,11 +57,8 @@ struct QrCodeResponse { #[derive(Debug, Clone, Deserialize)] struct QrStatusResponse { status: String, - #[serde(default)] bot_token: Option, - #[serde(default)] ilink_bot_id: Option, - #[serde(default)] baseurl: Option, }