use derive_more for Deref implementation on Handle

This commit is contained in:
2025-12-07 11:35:04 +00:00
parent fb910d7237
commit cb1c6b936e
2 changed files with 8 additions and 11 deletions
+6 -1
View File
@@ -9,7 +9,12 @@ repository = "https://github.com/elituf/haxor"
keywords = ["memory", "game", "hacking", "process"]
[dependencies]
derive_more = { version = "2", features = ["debug", "display", "from"] }
derive_more = { version = "2", features = [
"debug",
"deref",
"display",
"from",
] }
log = "0.4"
thiserror = "2"
windows = { version = "0.62", features = [
+2 -10
View File
@@ -1,24 +1,16 @@
use crate::error::Error;
use std::ops::Deref;
use derive_more::Deref;
use windows::Win32::{
Foundation::{CloseHandle, HANDLE, INVALID_HANDLE_VALUE},
System::Threading::{OpenProcess, PROCESS_ALL_ACCESS, PROCESS_VM_READ, PROCESS_VM_WRITE},
};
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Deref, Clone)]
pub struct Handle(pub HANDLE);
unsafe impl Send for Handle {}
unsafe impl Sync for Handle {}
impl Deref for Handle {
type Target = HANDLE;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Drop for Handle {
fn drop(&mut self) {
if let Err(why) = unsafe { CloseHandle(**self) } {