From c8377a83bdf716ed5ef05a2e733e6cb7a4817847 Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Wed, 20 Nov 2024 18:01:04 +0100 Subject: [PATCH 1/2] Derive `Hash` traits for `Metadata` and its transitive members --- src/dependency.rs | 2 +- src/lib.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/dependency.rs b/src/dependency.rs index efbe7bb5..293b9d9a 100644 --- a/src/dependency.rs +++ b/src/dependency.rs @@ -42,7 +42,7 @@ where Deserialize::deserialize(d).map(|x: Option<_>| x.unwrap_or_default()) } -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "builder", derive(Builder))] #[non_exhaustive] #[cfg_attr(feature = "builder", builder(pattern = "owned", setter(into)))] diff --git a/src/lib.rs b/src/lib.rs index 61d4cad5..584c7713 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,7 +127,7 @@ mod messages; /// precise format is an implementation detail and is subject to change. /// /// `Metadata` can be indexed by `PackageId`. -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] #[serde(transparent)] pub struct PackageId { /// The underlying string representation of id. @@ -145,7 +145,7 @@ fn is_null(value: &serde_json::Value) -> bool { matches!(value, serde_json::Value::Null) } -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "builder", derive(Builder))] #[non_exhaustive] #[cfg_attr(feature = "builder", builder(pattern = "owned", setter(into)))] @@ -224,7 +224,7 @@ impl<'a> std::ops::Index<&'a PackageId> for Metadata { } } -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)] #[serde(transparent)] /// A list of default workspace members. /// @@ -259,7 +259,7 @@ pub fn workspace_default_members_is_missing( workspace_default_members.0.is_none() } -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "builder", derive(Builder))] #[non_exhaustive] #[cfg_attr(feature = "builder", builder(pattern = "owned", setter(into)))] @@ -283,7 +283,7 @@ impl<'a> std::ops::Index<&'a PackageId> for Resolve { } } -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "builder", derive(Builder))] #[non_exhaustive] #[cfg_attr(feature = "builder", builder(pattern = "owned", setter(into)))] @@ -306,7 +306,7 @@ pub struct Node { pub features: Vec, } -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "builder", derive(Builder))] #[non_exhaustive] #[cfg_attr(feature = "builder", builder(pattern = "owned", setter(into)))] @@ -324,7 +324,7 @@ pub struct NodeDep { pub dep_kinds: Vec, } -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "builder", derive(Builder))] #[non_exhaustive] #[cfg_attr(feature = "builder", builder(pattern = "owned", setter(into)))] @@ -347,7 +347,7 @@ pub struct DepKindInfo { pub target: Option, } -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "builder", derive(Builder))] #[non_exhaustive] #[cfg_attr(feature = "builder", builder(pattern = "owned", setter(into)))] @@ -520,7 +520,7 @@ impl Package { /// /// It is possible to inspect the `repr` field, if the need arises, but its /// precise format is an implementation detail and is subject to change. -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)] #[serde(transparent)] pub struct Source { /// The underlying string representation of a source. @@ -752,7 +752,7 @@ impl From<&str> for CrateType { /// The Rust edition /// /// As of writing this comment rust editions 2024, 2027 and 2030 are not actually a thing yet but are parsed nonetheless for future proofing. -#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)] #[non_exhaustive] pub enum Edition { /// Edition 2015 From 24fe65d6dccfca29fd913d3632dc0c6c9151ad04 Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Wed, 20 Nov 2024 18:06:51 +0100 Subject: [PATCH 2/2] Fix a typo, while we're at it --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 584c7713..588fa607 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -817,7 +817,7 @@ pub enum CargoOpt { SomeFeatures(Vec), } -/// A builder for configurating `cargo metadata` invocation. +/// A builder for configuring `cargo metadata` invocation. #[derive(Debug, Clone, Default)] pub struct MetadataCommand { /// Path to `cargo` executable. If not set, this will use the