Skip to content

Commit 573adf1

Browse files
kennykerrmati865
authored andcommitted
Derive Copy, Clone, and Debug for handles (microsoft#3015)
1 parent 1740e6e commit 573adf1

File tree

105 files changed

+504
-5976
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+504
-5976
lines changed

crates/libs/bindgen/src/rust/handles.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub fn gen_win_handle(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
100100

101101
let mut tokens = quote! {
102102
#[repr(transparent)]
103-
#[derive(PartialEq, Eq)]
103+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
104104
pub struct #ident(pub #signature);
105105
#is_invalid
106106
#free
@@ -109,17 +109,6 @@ pub fn gen_win_handle(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
109109
unsafe { core::mem::zeroed() }
110110
}
111111
}
112-
impl Clone for #ident {
113-
fn clone(&self) -> Self {
114-
*self
115-
}
116-
}
117-
impl Copy for #ident {}
118-
impl core::fmt::Debug for #ident {
119-
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
120-
f.debug_tuple(#name).field(&self.0).finish()
121-
}
122-
}
123112
impl windows_core::TypeKind for #ident {
124113
type TypeKind = windows_core::CopyType;
125114
}

crates/libs/bindgen/src/rust/standalone.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,13 @@ pub fn standalone_imp(writer: &Writer) -> String {
6464
"GUID",
6565
quote! {
6666
#[repr(C)]
67+
#[derive(Clone, Copy)]
6768
pub struct GUID {
6869
pub data1: u32,
6970
pub data2: u16,
7071
pub data3: u16,
7172
pub data4: [u8; 8],
7273
}
73-
impl Copy for GUID {}
74-
impl Clone for GUID {
75-
fn clone(&self) -> Self {
76-
*self
77-
}
78-
}
7974
impl GUID {
8075
pub const fn from_u128(uuid: u128) -> Self {
8176
Self { data1: (uuid >> 96) as u32, data2: (uuid >> 80 & 0xffff) as u16, data3: (uuid >> 64 & 0xffff) as u16, data4: (uuid as u64).to_be_bytes() }

crates/libs/core/src/imp/bindings.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,18 +516,13 @@ impl Clone for FUNCDESC {
516516
pub type FUNCFLAGS = u16;
517517
pub type FUNCKIND = i32;
518518
#[repr(C)]
519+
#[derive(Clone, Copy)]
519520
pub struct GUID {
520521
pub data1: u32,
521522
pub data2: u16,
522523
pub data3: u16,
523524
pub data4: [u8; 8],
524525
}
525-
impl Copy for GUID {}
526-
impl Clone for GUID {
527-
fn clone(&self) -> Self {
528-
*self
529-
}
530-
}
531526
impl GUID {
532527
pub const fn from_u128(uuid: u128) -> Self {
533528
Self { data1: (uuid >> 96) as u32, data2: (uuid >> 80 & 0xffff) as u16, data3: (uuid >> 64 & 0xffff) as u16, data4: (uuid as u64).to_be_bytes() }

crates/libs/result/src/bindings.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,13 @@ pub const FORMAT_MESSAGE_FROM_SYSTEM: FORMAT_MESSAGE_OPTIONS = 4096u32;
2727
pub const FORMAT_MESSAGE_IGNORE_INSERTS: FORMAT_MESSAGE_OPTIONS = 512u32;
2828
pub type FORMAT_MESSAGE_OPTIONS = u32;
2929
#[repr(C)]
30+
#[derive(Clone, Copy)]
3031
pub struct GUID {
3132
pub data1: u32,
3233
pub data2: u16,
3334
pub data3: u16,
3435
pub data4: [u8; 8],
3536
}
36-
impl Copy for GUID {}
37-
impl Clone for GUID {
38-
fn clone(&self) -> Self {
39-
*self
40-
}
41-
}
4237
impl GUID {
4338
pub const fn from_u128(uuid: u128) -> Self {
4439
Self {

0 commit comments

Comments
 (0)