Remove redundant serde defaults from optional fields

This commit is contained in:
Coffee
2026-03-27 15:28:41 +08:00
parent 452f98c1b4
commit da733b4711
4 changed files with 7 additions and 57 deletions
-39
View File
@@ -80,23 +80,17 @@ pub struct GetConfigRequest {
#[derive(Debug, Clone, Deserialize)]
pub struct GetUpdatesResponse {
#[serde(default)]
pub ret: Option<i32>,
#[serde(default)]
pub errcode: Option<i32>,
#[serde(default)]
pub errmsg: Option<String>,
#[serde(default)]
pub msgs: Vec<WechatMessage>,
#[serde(default)]
pub get_updates_buf: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct GetUploadUrlResponse {
#[serde(default)]
pub upload_param: Option<String>,
#[serde(default)]
pub thumb_upload_param: Option<String>,
}
@@ -128,17 +122,11 @@ pub struct OutboundWechatMessage {
#[derive(Debug, Clone, Deserialize)]
pub struct WechatMessage {
#[serde(default)]
pub message_id: Option<i64>,
#[serde(default)]
pub from_user_id: Option<String>,
#[serde(default)]
pub to_user_id: Option<String>,
#[serde(default)]
pub session_id: Option<String>,
#[serde(default)]
pub message_type: Option<i32>,
#[serde(default)]
pub context_token: Option<String>,
#[serde(default)]
pub item_list: Vec<MessageItem>,
@@ -146,33 +134,23 @@ pub struct WechatMessage {
#[derive(Debug, Clone, Deserialize)]
pub struct GetConfigResponse {
#[serde(default)]
pub ret: Option<i32>,
#[serde(default)]
pub errmsg: Option<String>,
#[serde(default)]
pub typing_ticket: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct SendTypingResponse {
#[serde(default)]
pub ret: Option<i32>,
#[serde(default)]
pub errmsg: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MessageItem {
#[serde(default)]
pub r#type: Option<i32>,
#[serde(default)]
pub text_item: Option<TextItem>,
#[serde(default)]
pub image_item: Option<ImageItem>,
#[serde(default)]
pub voice_item: Option<VoiceItem>,
#[serde(default)]
pub file_item: Option<FileItem>,
}
@@ -183,56 +161,39 @@ pub struct TextItem {
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct CdnMedia {
#[serde(default)]
pub encrypt_query_param: Option<String>,
#[serde(default)]
pub aes_key: Option<String>,
#[serde(default)]
pub encrypt_type: Option<i32>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ImageItem {
#[serde(default)]
pub media: Option<CdnMedia>,
#[serde(default)]
pub aeskey: Option<String>,
#[serde(default)]
pub mid_size: Option<u64>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct VoiceItem {
#[serde(default)]
pub media: Option<CdnMedia>,
#[serde(default)]
pub encode_type: Option<i32>,
#[serde(default)]
pub playtime: Option<u64>,
#[serde(default)]
pub text: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FileItem {
#[serde(default)]
pub media: Option<CdnMedia>,
#[serde(default)]
pub file_name: Option<String>,
#[serde(default)]
pub len: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct OutboundMetadata {
pub from_user_id: String,
#[serde(default)]
pub to_user_id: Option<String>,
#[serde(default)]
pub message_id: Option<i64>,
#[serde(default)]
pub session_id: Option<String>,
#[serde(default)]
pub context_token: Option<String>,
}
@@ -16,7 +16,6 @@ const WECHAT_SILK_SAMPLE_RATE_HZ: i32 = 24_000;
#[derive(Debug, Deserialize)]
struct WechatAttachmentExtras {
#[serde(default)]
wechat_aes_key: Option<String>,
}
+7 -14
View File
@@ -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<Box<ExtensionSource>>,
/// 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<String>,
}
@@ -88,17 +88,14 @@ pub enum ExtensionSource {
/// Downloadable WASM binary.
WasmDownload {
wasm_url: String,
#[serde(default)]
capabilities_url: Option<String>,
},
/// Build from local source directory.
WasmBuildable {
#[serde(alias = "repo_url")]
source_dir: String,
#[serde(default)]
build_dir: Option<String>,
/// Crate name used to locate the build artifact binary.
#[serde(default)]
crate_name: Option<String>,
},
/// 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<String>,
#[serde(default)]
callback_type: Option<String>,
#[serde(default)]
instructions: Option<String>,
#[serde(default)]
setup_url: Option<String>,
#[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<String>,
}
@@ -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<String>,
/// 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<String>,
}
@@ -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<String>,
/// 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<bool>,
}
-3
View File
@@ -57,11 +57,8 @@ struct QrCodeResponse {
#[derive(Debug, Clone, Deserialize)]
struct QrStatusResponse {
status: String,
#[serde(default)]
bot_token: Option<String>,
#[serde(default)]
ilink_bot_id: Option<String>,
#[serde(default)]
baseurl: Option<String>,
}