Skip to content

Commit

Permalink
Derive Copy, Clone, and Debug for handles (microsoft#3015)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored and mati865 committed Jun 15, 2024
1 parent 1740e6e commit 573adf1
Show file tree
Hide file tree
Showing 105 changed files with 504 additions and 5,976 deletions.
13 changes: 1 addition & 12 deletions crates/libs/bindgen/src/rust/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn gen_win_handle(writer: &Writer, def: metadata::TypeDef) -> TokenStream {

let mut tokens = quote! {
#[repr(transparent)]
#[derive(PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct #ident(pub #signature);
#is_invalid
#free
Expand All @@ -109,17 +109,6 @@ pub fn gen_win_handle(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
unsafe { core::mem::zeroed() }
}
}
impl Clone for #ident {
fn clone(&self) -> Self {
*self
}
}
impl Copy for #ident {}
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()
}
}
impl windows_core::TypeKind for #ident {
type TypeKind = windows_core::CopyType;
}
Expand Down
7 changes: 1 addition & 6 deletions crates/libs/bindgen/src/rust/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,13 @@ pub fn standalone_imp(writer: &Writer) -> String {
"GUID",
quote! {
#[repr(C)]
#[derive(Clone, Copy)]
pub struct GUID {
pub data1: u32,
pub data2: u16,
pub data3: u16,
pub data4: [u8; 8],
}
impl Copy for GUID {}
impl Clone for GUID {
fn clone(&self) -> Self {
*self
}
}
impl GUID {
pub const fn from_u128(uuid: u128) -> Self {
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() }
Expand Down
7 changes: 1 addition & 6 deletions crates/libs/core/src/imp/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,18 +516,13 @@ impl Clone for FUNCDESC {
pub type FUNCFLAGS = u16;
pub type FUNCKIND = i32;
#[repr(C)]
#[derive(Clone, Copy)]
pub struct GUID {
pub data1: u32,
pub data2: u16,
pub data3: u16,
pub data4: [u8; 8],
}
impl Copy for GUID {}
impl Clone for GUID {
fn clone(&self) -> Self {
*self
}
}
impl GUID {
pub const fn from_u128(uuid: u128) -> Self {
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() }
Expand Down
7 changes: 1 addition & 6 deletions crates/libs/result/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,13 @@ pub const FORMAT_MESSAGE_FROM_SYSTEM: FORMAT_MESSAGE_OPTIONS = 4096u32;
pub const FORMAT_MESSAGE_IGNORE_INSERTS: FORMAT_MESSAGE_OPTIONS = 512u32;
pub type FORMAT_MESSAGE_OPTIONS = u32;
#[repr(C)]
#[derive(Clone, Copy)]
pub struct GUID {
pub data1: u32,
pub data2: u16,
pub data3: u16,
pub data4: [u8; 8],
}
impl Copy for GUID {}
impl Clone for GUID {
fn clone(&self) -> Self {
*self
}
}
impl GUID {
pub const fn from_u128(uuid: u128) -> Self {
Self {
Expand Down
Loading

0 comments on commit 573adf1

Please sign in to comment.