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 Copy, Clone, Default for enums #2760

Merged
merged 5 commits into from
Dec 29, 2023
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.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
39 changes: 10 additions & 29 deletions crates/libs/bindgen/src/rust/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
})
.collect();

let eq = if writer.sys {
quote! {}
let derive = if writer.sys {
if is_scoped {
quote! {
#[derive(::core::marker::Copy, ::core::clone::Clone)]
}
} else {
quote! {}
}
} else {
quote! {
// Unfortunately, Rust requires these to be derived to allow constant patterns.
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::marker::Copy, ::core::clone::Clone, ::core::default::Default)]
}
};

Expand All @@ -43,7 +48,7 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
#doc
#features
#[repr(transparent)]
#eq
#derive
pub struct #ident(pub #underlying_type);
}
} else {
Expand All @@ -69,30 +74,6 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
});
}

if is_scoped || !writer.sys {
tokens.combine(&quote! {
#features
impl ::core::marker::Copy for #ident {}
#features
impl ::core::clone::Clone for #ident {
fn clone(&self) -> Self {
*self
}
}
});
}

if !writer.sys {
tokens.combine(&quote! {
#features
impl ::core::default::Default for #ident {
fn default() -> Self {
Self(0)
}
}
});
}

if !writer.sys {
let name = type_name.name;
tokens.combine(&quote! {
Expand Down
26 changes: 2 additions & 24 deletions crates/libs/core/src/imp/com_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,8 @@ where
}
pub const AGILEREFERENCE_DEFAULT: AgileReferenceOptions = AgileReferenceOptions(0i32);
#[repr(transparent)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::marker::Copy, ::core::clone::Clone, ::core::default::Default)]
pub struct AgileReferenceOptions(pub i32);
impl ::core::marker::Copy for AgileReferenceOptions {}
impl ::core::clone::Clone for AgileReferenceOptions {
fn clone(&self) -> Self {
*self
}
}
impl ::core::default::Default for AgileReferenceOptions {
fn default() -> Self {
Self(0)
}
}
impl ::windows_core::TypeKind for AgileReferenceOptions {
type TypeKind = ::windows_core::CopyType;
}
Expand Down Expand Up @@ -952,7 +941,7 @@ impl ::core::default::Default for Point {
}
}
#[repr(transparent)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::marker::Copy, ::core::clone::Clone, ::core::default::Default)]
pub struct PropertyType(pub i32);
impl PropertyType {
pub const Empty: Self = Self(0i32);
Expand Down Expand Up @@ -997,17 +986,6 @@ impl PropertyType {
pub const RectArray: Self = Self(1043i32);
pub const OtherTypeArray: Self = Self(1044i32);
}
impl ::core::marker::Copy for PropertyType {}
impl ::core::clone::Clone for PropertyType {
fn clone(&self) -> Self {
*self
}
}
impl ::core::default::Default for PropertyType {
fn default() -> Self {
Self(0)
}
}
impl ::windows_core::TypeKind for PropertyType {
type TypeKind = ::windows_core::CopyType;
}
Expand Down
7 changes: 1 addition & 6 deletions crates/libs/sys/src/Windows/Win32/Media/Audio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ pub type AudioSessionDisconnectReason = i32;
pub type AudioSessionState = i32;
pub type AudioStateMonitorSoundLevel = i32;
#[repr(transparent)]
#[derive(::core::marker::Copy, ::core::clone::Clone)]
pub struct ConnectorType(pub i32);
impl ConnectorType {
pub const Unknown_Connector: Self = Self(0i32);
Expand All @@ -931,12 +932,6 @@ impl ConnectorType {
pub const Software_Fixed: Self = Self(4i32);
pub const Network: Self = Self(5i32);
}
impl ::core::marker::Copy for ConnectorType {}
impl ::core::clone::Clone for ConnectorType {
fn clone(&self) -> Self {
*self
}
}
pub type DataFlow = i32;
pub type EDataFlow = i32;
pub type ERole = i32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,7 @@ pub type SECPKG_NAME_TYPE = i32;
pub type SECPKG_PACKAGE_CHANGE_TYPE = u32;
pub type SECPKG_SESSIONINFO_TYPE = i32;
#[repr(transparent)]
#[derive(::core::marker::Copy, ::core::clone::Clone)]
pub struct SECURITY_LOGON_TYPE(pub i32);
impl SECURITY_LOGON_TYPE {
pub const UndefinedLogonType: Self = Self(0i32);
Expand All @@ -2277,12 +2278,6 @@ impl SECURITY_LOGON_TYPE {
pub const CachedRemoteInteractive: Self = Self(12i32);
pub const CachedUnlock: Self = Self(13i32);
}
impl ::core::marker::Copy for SECURITY_LOGON_TYPE {}
impl ::core::clone::Clone for SECURITY_LOGON_TYPE {
fn clone(&self) -> Self {
*self
}
}
pub type SECURITY_PACKAGE_OPTIONS_TYPE = u32;
pub type SEC_APPLICATION_PROTOCOL_NEGOTIATION_EXT = i32;
pub type SEC_APPLICATION_PROTOCOL_NEGOTIATION_STATUS = i32;
Expand Down
14 changes: 2 additions & 12 deletions crates/libs/sys/src/Windows/Win32/Security/Cryptography/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3953,24 +3953,20 @@ pub type ECC_CURVE_TYPE_ENUM = i32;
pub type HASHALGORITHM_ENUM = i32;
pub type HTTPSPOLICY_CALLBACK_DATA_AUTH_TYPE = u32;
#[repr(transparent)]
#[derive(::core::marker::Copy, ::core::clone::Clone)]
pub struct HandleType(pub i32);
impl HandleType {
pub const Asymmetric: Self = Self(1i32);
pub const Symmetric: Self = Self(2i32);
pub const Transform: Self = Self(3i32);
pub const Hash: Self = Self(4i32);
}
impl ::core::marker::Copy for HandleType {}
impl ::core::clone::Clone for HandleType {
fn clone(&self) -> Self {
*self
}
}
pub type MSCEPSetupProperty = i32;
pub type NCRYPT_ALGORITHM_NAME_CLASS = u32;
pub type NCRYPT_FLAGS = u32;
pub type NCRYPT_OPERATION = u32;
#[repr(transparent)]
#[derive(::core::marker::Copy, ::core::clone::Clone)]
pub struct PaddingMode(pub i32);
impl PaddingMode {
pub const None: Self = Self(1i32);
Expand All @@ -3979,12 +3975,6 @@ impl PaddingMode {
pub const ANSIX923: Self = Self(4i32);
pub const ISO10126: Self = Self(5i32);
}
impl ::core::marker::Copy for PaddingMode {}
impl ::core::clone::Clone for PaddingMode {
fn clone(&self) -> Self {
*self
}
}
pub type SIGNER_CERT_CHOICE = u32;
pub type SIGNER_CERT_POLICY = u32;
pub type SIGNER_PRIVATE_KEY_CHOICE = u32;
Expand Down
42 changes: 6 additions & 36 deletions crates/libs/sys/src/Windows/Win32/System/WindowsProgramming/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,79 +941,49 @@ pub const WM_INTERIM: u32 = 268u32;
pub const WM_WNT_CONVERTREQUESTEX: u32 = 265u32;
pub const WinStationInformation: WINSTATIONINFOCLASS = 8i32;
#[repr(transparent)]
#[derive(::core::marker::Copy, ::core::clone::Clone)]
pub struct CameraUIControlCaptureMode(pub i32);
impl CameraUIControlCaptureMode {
pub const PhotoOrVideo: Self = Self(0i32);
pub const Photo: Self = Self(1i32);
pub const Video: Self = Self(2i32);
}
impl ::core::marker::Copy for CameraUIControlCaptureMode {}
impl ::core::clone::Clone for CameraUIControlCaptureMode {
fn clone(&self) -> Self {
*self
}
}
#[repr(transparent)]
#[derive(::core::marker::Copy, ::core::clone::Clone)]
pub struct CameraUIControlLinearSelectionMode(pub i32);
impl CameraUIControlLinearSelectionMode {
pub const Single: Self = Self(0i32);
pub const Multiple: Self = Self(1i32);
}
impl ::core::marker::Copy for CameraUIControlLinearSelectionMode {}
impl ::core::clone::Clone for CameraUIControlLinearSelectionMode {
fn clone(&self) -> Self {
*self
}
}
#[repr(transparent)]
#[derive(::core::marker::Copy, ::core::clone::Clone)]
pub struct CameraUIControlMode(pub i32);
impl CameraUIControlMode {
pub const Browse: Self = Self(0i32);
pub const Linear: Self = Self(1i32);
}
impl ::core::marker::Copy for CameraUIControlMode {}
impl ::core::clone::Clone for CameraUIControlMode {
fn clone(&self) -> Self {
*self
}
}
#[repr(transparent)]
#[derive(::core::marker::Copy, ::core::clone::Clone)]
pub struct CameraUIControlPhotoFormat(pub i32);
impl CameraUIControlPhotoFormat {
pub const Jpeg: Self = Self(0i32);
pub const Png: Self = Self(1i32);
pub const JpegXR: Self = Self(2i32);
}
impl ::core::marker::Copy for CameraUIControlPhotoFormat {}
impl ::core::clone::Clone for CameraUIControlPhotoFormat {
fn clone(&self) -> Self {
*self
}
}
#[repr(transparent)]
#[derive(::core::marker::Copy, ::core::clone::Clone)]
pub struct CameraUIControlVideoFormat(pub i32);
impl CameraUIControlVideoFormat {
pub const Mp4: Self = Self(0i32);
pub const Wmv: Self = Self(1i32);
}
impl ::core::marker::Copy for CameraUIControlVideoFormat {}
impl ::core::clone::Clone for CameraUIControlVideoFormat {
fn clone(&self) -> Self {
*self
}
}
#[repr(transparent)]
#[derive(::core::marker::Copy, ::core::clone::Clone)]
pub struct CameraUIControlViewType(pub i32);
impl CameraUIControlViewType {
pub const SingleItem: Self = Self(0i32);
pub const ItemList: Self = Self(1i32);
}
impl ::core::marker::Copy for CameraUIControlViewType {}
impl ::core::clone::Clone for CameraUIControlViewType {
fn clone(&self) -> Self {
*self
}
}
pub type DECISION_LOCATION = i32;
pub type FEATURE_CHANGE_TIME = i32;
pub type FEATURE_ENABLED_STATE = i32;
Expand Down
52 changes: 4 additions & 48 deletions crates/libs/windows/src/Windows/AI/MachineLearning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4099,7 +4099,7 @@ impl ::windows_core::CanTryInto<ITensor> for TensorUInt8Bit {}
unsafe impl ::core::marker::Send for TensorUInt8Bit {}
unsafe impl ::core::marker::Sync for TensorUInt8Bit {}
#[repr(transparent)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::marker::Copy, ::core::clone::Clone, ::core::default::Default)]
pub struct LearningModelDeviceKind(pub i32);
impl LearningModelDeviceKind {
pub const Default: Self = Self(0i32);
Expand All @@ -4108,17 +4108,6 @@ impl LearningModelDeviceKind {
pub const DirectXHighPerformance: Self = Self(3i32);
pub const DirectXMinPower: Self = Self(4i32);
}
impl ::core::marker::Copy for LearningModelDeviceKind {}
impl ::core::clone::Clone for LearningModelDeviceKind {
fn clone(&self) -> Self {
*self
}
}
impl ::core::default::Default for LearningModelDeviceKind {
fn default() -> Self {
Self(0)
}
}
impl ::windows_core::TypeKind for LearningModelDeviceKind {
type TypeKind = ::windows_core::CopyType;
}
Expand All @@ -4131,25 +4120,14 @@ impl ::windows_core::RuntimeType for LearningModelDeviceKind {
const SIGNATURE: ::windows_core::imp::ConstBuffer = ::windows_core::imp::ConstBuffer::from_slice(b"enum(Windows.AI.MachineLearning.LearningModelDeviceKind;i4)");
}
#[repr(transparent)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::marker::Copy, ::core::clone::Clone, ::core::default::Default)]
pub struct LearningModelFeatureKind(pub i32);
impl LearningModelFeatureKind {
pub const Tensor: Self = Self(0i32);
pub const Sequence: Self = Self(1i32);
pub const Map: Self = Self(2i32);
pub const Image: Self = Self(3i32);
}
impl ::core::marker::Copy for LearningModelFeatureKind {}
impl ::core::clone::Clone for LearningModelFeatureKind {
fn clone(&self) -> Self {
*self
}
}
impl ::core::default::Default for LearningModelFeatureKind {
fn default() -> Self {
Self(0)
}
}
impl ::windows_core::TypeKind for LearningModelFeatureKind {
type TypeKind = ::windows_core::CopyType;
}
Expand All @@ -4162,24 +4140,13 @@ impl ::windows_core::RuntimeType for LearningModelFeatureKind {
const SIGNATURE: ::windows_core::imp::ConstBuffer = ::windows_core::imp::ConstBuffer::from_slice(b"enum(Windows.AI.MachineLearning.LearningModelFeatureKind;i4)");
}
#[repr(transparent)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::marker::Copy, ::core::clone::Clone, ::core::default::Default)]
pub struct LearningModelPixelRange(pub i32);
impl LearningModelPixelRange {
pub const ZeroTo255: Self = Self(0i32);
pub const ZeroToOne: Self = Self(1i32);
pub const MinusOneToOne: Self = Self(2i32);
}
impl ::core::marker::Copy for LearningModelPixelRange {}
impl ::core::clone::Clone for LearningModelPixelRange {
fn clone(&self) -> Self {
*self
}
}
impl ::core::default::Default for LearningModelPixelRange {
fn default() -> Self {
Self(0)
}
}
impl ::windows_core::TypeKind for LearningModelPixelRange {
type TypeKind = ::windows_core::CopyType;
}
Expand All @@ -4192,7 +4159,7 @@ impl ::windows_core::RuntimeType for LearningModelPixelRange {
const SIGNATURE: ::windows_core::imp::ConstBuffer = ::windows_core::imp::ConstBuffer::from_slice(b"enum(Windows.AI.MachineLearning.LearningModelPixelRange;i4)");
}
#[repr(transparent)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::marker::Copy, ::core::clone::Clone, ::core::default::Default)]
pub struct TensorKind(pub i32);
impl TensorKind {
pub const Undefined: Self = Self(0i32);
Expand All @@ -4212,17 +4179,6 @@ impl TensorKind {
pub const Complex64: Self = Self(14i32);
pub const Complex128: Self = Self(15i32);
}
impl ::core::marker::Copy for TensorKind {}
impl ::core::clone::Clone for TensorKind {
fn clone(&self) -> Self {
*self
}
}
impl ::core::default::Default for TensorKind {
fn default() -> Self {
Self(0)
}
}
impl ::windows_core::TypeKind for TensorKind {
type TypeKind = ::windows_core::CopyType;
}
Expand Down
Loading