From dc53ab2b2dc7d2778dffc1bccd34b3ccf36ee0ae Mon Sep 17 00:00:00 2001 From: zjp Date: Wed, 2 Oct 2024 20:18:04 +0800 Subject: [PATCH] fix(Metadata): set a default value on workspace_default_members deserialization --- src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index cc8791c5..0589fb9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -158,6 +158,7 @@ pub struct Metadata { /// The list of default workspace members /// /// This not available if running with a version of Cargo older than 1.71. + #[serde(default = "empty_workspace_default_members")] #[serde(skip_serializing_if = "workspace_default_members_is_missing")] pub workspace_default_members: WorkspaceDefaultMembers, /// Dependencies graph @@ -259,6 +260,14 @@ pub fn workspace_default_members_is_missing( workspace_default_members.0.is_none() } +/// A default value when Metadata is deserialized with WorkspaceDefaultMembers skipped. +/// +/// We use this function for now because WorkspaceDefaultMembers doesn't implement Default. +#[doc(hidden)] +pub fn empty_workspace_default_members() -> WorkspaceDefaultMembers { + WorkspaceDefaultMembers(None) +} + #[derive(Clone, Serialize, Deserialize, Debug)] #[cfg_attr(feature = "builder", derive(Builder))] #[non_exhaustive]