Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive PartialEq and Eq for scoped enums to support constant patterns #1438

Merged
merged 2 commits into from Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions crates/libs/bindgen/src/enums.rs
Expand Up @@ -36,10 +36,20 @@ pub fn gen(def: &TypeDef, gen: &Gen) -> TokenStream {
}
});

let eq = if gen.sys {
quote! {}
} else {
quote! {
// Unfortunately, Rust requires these to be derived to allow constant patterns.
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq)]
}
};

quote! {
#doc
#features
#[repr(transparent)]
#eq
pub struct #ident(pub #underlying_type);
#features
impl #ident {
Expand Down Expand Up @@ -79,14 +89,6 @@ pub fn gen(def: &TypeDef, gen: &Gen) -> TokenStream {
type Abi = Self;
}
#features
impl ::core::cmp::PartialEq for #ident {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
#features
impl ::core::cmp::Eq for #ident {}
#features
impl ::core::fmt::Debug for #ident {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple(#name).field(&self.0).finish()
Expand Down
27 changes: 3 additions & 24 deletions crates/libs/windows/src/Windows/AI/MachineLearning/Preview/mod.rs
Expand Up @@ -2,6 +2,7 @@
#[doc = "*Required features: 'AI_MachineLearning_Preview', 'deprecated'*"]
#[cfg(feature = "deprecated")]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct FeatureElementKindPreview(pub i32);
#[cfg(feature = "deprecated")]
impl FeatureElementKindPreview {
Expand Down Expand Up @@ -35,14 +36,6 @@ unsafe impl ::windows::core::Abi for FeatureElementKindPreview {
type Abi = Self;
}
#[cfg(feature = "deprecated")]
impl ::core::cmp::PartialEq for FeatureElementKindPreview {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
#[cfg(feature = "deprecated")]
impl ::core::cmp::Eq for FeatureElementKindPreview {}
#[cfg(feature = "deprecated")]
impl ::core::fmt::Debug for FeatureElementKindPreview {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("FeatureElementKindPreview").field(&self.0).finish()
Expand Down Expand Up @@ -1230,6 +1223,7 @@ impl<'a> ::windows::core::IntoParam<'a, ::windows::core::IInspectable> for &Lear
#[doc = "*Required features: 'AI_MachineLearning_Preview', 'deprecated'*"]
#[cfg(feature = "deprecated")]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct LearningModelDeviceKindPreview(pub i32);
#[cfg(feature = "deprecated")]
impl LearningModelDeviceKindPreview {
Expand All @@ -1253,14 +1247,6 @@ unsafe impl ::windows::core::Abi for LearningModelDeviceKindPreview {
type Abi = Self;
}
#[cfg(feature = "deprecated")]
impl ::core::cmp::PartialEq for LearningModelDeviceKindPreview {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
#[cfg(feature = "deprecated")]
impl ::core::cmp::Eq for LearningModelDeviceKindPreview {}
#[cfg(feature = "deprecated")]
impl ::core::fmt::Debug for LearningModelDeviceKindPreview {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("LearningModelDeviceKindPreview").field(&self.0).finish()
Expand Down Expand Up @@ -1383,6 +1369,7 @@ impl<'a> ::windows::core::IntoParam<'a, ::windows::core::IInspectable> for &Lear
#[doc = "*Required features: 'AI_MachineLearning_Preview', 'deprecated'*"]
#[cfg(feature = "deprecated")]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct LearningModelFeatureKindPreview(pub i32);
#[cfg(feature = "deprecated")]
impl LearningModelFeatureKindPreview {
Expand All @@ -1405,14 +1392,6 @@ unsafe impl ::windows::core::Abi for LearningModelFeatureKindPreview {
type Abi = Self;
}
#[cfg(feature = "deprecated")]
impl ::core::cmp::PartialEq for LearningModelFeatureKindPreview {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
#[cfg(feature = "deprecated")]
impl ::core::cmp::Eq for LearningModelFeatureKindPreview {}
#[cfg(feature = "deprecated")]
impl ::core::fmt::Debug for LearningModelFeatureKindPreview {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("LearningModelFeatureKindPreview").field(&self.0).finish()
Expand Down
28 changes: 4 additions & 24 deletions crates/libs/windows/src/Windows/AI/MachineLearning/mod.rs
Expand Up @@ -2521,6 +2521,7 @@ unsafe impl ::core::marker::Send for LearningModelDevice {}
unsafe impl ::core::marker::Sync for LearningModelDevice {}
#[doc = "*Required features: 'AI_MachineLearning'*"]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct LearningModelDeviceKind(pub i32);
impl LearningModelDeviceKind {
pub const Default: Self = Self(0i32);
Expand All @@ -2538,12 +2539,6 @@ impl ::core::clone::Clone for LearningModelDeviceKind {
unsafe impl ::windows::core::Abi for LearningModelDeviceKind {
type Abi = Self;
}
impl ::core::cmp::PartialEq for LearningModelDeviceKind {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for LearningModelDeviceKind {}
impl ::core::fmt::Debug for LearningModelDeviceKind {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("LearningModelDeviceKind").field(&self.0).finish()
Expand Down Expand Up @@ -2663,6 +2658,7 @@ unsafe impl ::core::marker::Send for LearningModelEvaluationResult {}
unsafe impl ::core::marker::Sync for LearningModelEvaluationResult {}
#[doc = "*Required features: 'AI_MachineLearning'*"]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct LearningModelFeatureKind(pub i32);
impl LearningModelFeatureKind {
pub const Tensor: Self = Self(0i32);
Expand All @@ -2679,12 +2675,6 @@ impl ::core::clone::Clone for LearningModelFeatureKind {
unsafe impl ::windows::core::Abi for LearningModelFeatureKind {
type Abi = Self;
}
impl ::core::cmp::PartialEq for LearningModelFeatureKind {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for LearningModelFeatureKind {}
impl ::core::fmt::Debug for LearningModelFeatureKind {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("LearningModelFeatureKind").field(&self.0).finish()
Expand All @@ -2698,6 +2688,7 @@ impl ::windows::core::DefaultType for LearningModelFeatureKind {
}
#[doc = "*Required features: 'AI_MachineLearning'*"]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct LearningModelPixelRange(pub i32);
impl LearningModelPixelRange {
pub const ZeroTo255: Self = Self(0i32);
Expand All @@ -2713,12 +2704,6 @@ impl ::core::clone::Clone for LearningModelPixelRange {
unsafe impl ::windows::core::Abi for LearningModelPixelRange {
type Abi = Self;
}
impl ::core::cmp::PartialEq for LearningModelPixelRange {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for LearningModelPixelRange {}
impl ::core::fmt::Debug for LearningModelPixelRange {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("LearningModelPixelRange").field(&self.0).finish()
Expand Down Expand Up @@ -5653,6 +5638,7 @@ unsafe impl ::core::marker::Send for TensorInt8Bit {}
unsafe impl ::core::marker::Sync for TensorInt8Bit {}
#[doc = "*Required features: 'AI_MachineLearning'*"]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct TensorKind(pub i32);
impl TensorKind {
pub const Undefined: Self = Self(0i32);
Expand Down Expand Up @@ -5681,12 +5667,6 @@ impl ::core::clone::Clone for TensorKind {
unsafe impl ::windows::core::Abi for TensorKind {
type Abi = Self;
}
impl ::core::cmp::PartialEq for TensorKind {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for TensorKind {}
impl ::core::fmt::Debug for TensorKind {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("TensorKind").field(&self.0).finish()
Expand Down
14 changes: 2 additions & 12 deletions crates/libs/windows/src/Windows/ApplicationModel/Activation/mod.rs
@@ -1,6 +1,7 @@
#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals, clashing_extern_declarations, clippy::all)]
#[doc = "*Required features: 'ApplicationModel_Activation'*"]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct ActivationKind(pub i32);
impl ActivationKind {
pub const Launch: Self = Self(0i32);
Expand Down Expand Up @@ -57,12 +58,6 @@ impl ::core::clone::Clone for ActivationKind {
unsafe impl ::windows::core::Abi for ActivationKind {
type Abi = Self;
}
impl ::core::cmp::PartialEq for ActivationKind {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for ActivationKind {}
impl ::core::fmt::Debug for ActivationKind {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("ActivationKind").field(&self.0).finish()
Expand All @@ -76,6 +71,7 @@ impl ::windows::core::DefaultType for ActivationKind {
}
#[doc = "*Required features: 'ApplicationModel_Activation'*"]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct ApplicationExecutionState(pub i32);
impl ApplicationExecutionState {
pub const NotRunning: Self = Self(0i32);
Expand All @@ -93,12 +89,6 @@ impl ::core::clone::Clone for ApplicationExecutionState {
unsafe impl ::windows::core::Abi for ApplicationExecutionState {
type Abi = Self;
}
impl ::core::cmp::PartialEq for ApplicationExecutionState {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for ApplicationExecutionState {}
impl ::core::fmt::Debug for ApplicationExecutionState {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("ApplicationExecutionState").field(&self.0).finish()
Expand Down
28 changes: 4 additions & 24 deletions crates/libs/windows/src/Windows/ApplicationModel/AppService/mod.rs
Expand Up @@ -102,6 +102,7 @@ unsafe impl ::core::marker::Send for AppServiceClosedEventArgs {}
unsafe impl ::core::marker::Sync for AppServiceClosedEventArgs {}
#[doc = "*Required features: 'ApplicationModel_AppService'*"]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct AppServiceClosedStatus(pub i32);
impl AppServiceClosedStatus {
pub const Completed: Self = Self(0i32);
Expand All @@ -118,12 +119,6 @@ impl ::core::clone::Clone for AppServiceClosedStatus {
unsafe impl ::windows::core::Abi for AppServiceClosedStatus {
type Abi = Self;
}
impl ::core::cmp::PartialEq for AppServiceClosedStatus {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for AppServiceClosedStatus {}
impl ::core::fmt::Debug for AppServiceClosedStatus {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("AppServiceClosedStatus").field(&self.0).finish()
Expand Down Expand Up @@ -360,6 +355,7 @@ unsafe impl ::core::marker::Send for AppServiceConnection {}
unsafe impl ::core::marker::Sync for AppServiceConnection {}
#[doc = "*Required features: 'ApplicationModel_AppService'*"]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct AppServiceConnectionStatus(pub i32);
impl AppServiceConnectionStatus {
pub const Success: Self = Self(0i32);
Expand All @@ -384,12 +380,6 @@ impl ::core::clone::Clone for AppServiceConnectionStatus {
unsafe impl ::windows::core::Abi for AppServiceConnectionStatus {
type Abi = Self;
}
impl ::core::cmp::PartialEq for AppServiceConnectionStatus {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for AppServiceConnectionStatus {}
impl ::core::fmt::Debug for AppServiceConnectionStatus {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("AppServiceConnectionStatus").field(&self.0).finish()
Expand Down Expand Up @@ -751,6 +741,7 @@ unsafe impl ::core::marker::Send for AppServiceResponse {}
unsafe impl ::core::marker::Sync for AppServiceResponse {}
#[doc = "*Required features: 'ApplicationModel_AppService'*"]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct AppServiceResponseStatus(pub i32);
impl AppServiceResponseStatus {
pub const Success: Self = Self(0i32);
Expand All @@ -774,12 +765,6 @@ impl ::core::clone::Clone for AppServiceResponseStatus {
unsafe impl ::windows::core::Abi for AppServiceResponseStatus {
type Abi = Self;
}
impl ::core::cmp::PartialEq for AppServiceResponseStatus {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for AppServiceResponseStatus {}
impl ::core::fmt::Debug for AppServiceResponseStatus {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("AppServiceResponseStatus").field(&self.0).finish()
Expand Down Expand Up @@ -1290,6 +1275,7 @@ unsafe impl ::core::marker::Send for StatelessAppServiceResponse {}
unsafe impl ::core::marker::Sync for StatelessAppServiceResponse {}
#[doc = "*Required features: 'ApplicationModel_AppService'*"]
#[repr(transparent)]
#[derive(:: core :: cmp :: PartialEq, :: core :: cmp :: Eq)]
pub struct StatelessAppServiceResponseStatus(pub i32);
impl StatelessAppServiceResponseStatus {
pub const Success: Self = Self(0i32);
Expand Down Expand Up @@ -1317,12 +1303,6 @@ impl ::core::clone::Clone for StatelessAppServiceResponseStatus {
unsafe impl ::windows::core::Abi for StatelessAppServiceResponseStatus {
type Abi = Self;
}
impl ::core::cmp::PartialEq for StatelessAppServiceResponseStatus {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for StatelessAppServiceResponseStatus {}
impl ::core::fmt::Debug for StatelessAppServiceResponseStatus {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("StatelessAppServiceResponseStatus").field(&self.0).finish()
Expand Down