From 057a8eeb023ce07e971e9ed98111a269df8049bb Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 3 Jan 2022 14:27:39 -0800 Subject: fix(windows-kernel-rs): impl Into to impl From --- crates/windows-kernel-rs/src/memory.rs | 48 ++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 8 deletions(-) (limited to 'crates/windows-kernel-rs/src/memory.rs') diff --git a/crates/windows-kernel-rs/src/memory.rs b/crates/windows-kernel-rs/src/memory.rs index cb5d2e9..d2ad77b 100644 --- a/crates/windows-kernel-rs/src/memory.rs +++ b/crates/windows-kernel-rs/src/memory.rs @@ -30,19 +30,33 @@ impl From for PhysicalAddress { fn from(value: u64) -> Self { Self(value) } } -impl Into for PhysicalAddress { - fn into(self) -> u64 { self.0 } +// impl Into for PhysicalAddress { +// fn into(self) -> u64 { self.0 } +// } +impl From for u64 { + fn from(p: PhysicalAddress) -> Self { + p.0 + } } impl From for PhysicalAddress { fn from(value: PHYSICAL_ADDRESS) -> Self { Self(unsafe { value.QuadPart } as _) } } -impl Into for PhysicalAddress { - fn into(self) -> PHYSICAL_ADDRESS { +// impl Into for PhysicalAddress { +// fn into(self) -> PHYSICAL_ADDRESS { +// let mut addr: PHYSICAL_ADDRESS = unsafe { core::mem::zeroed() }; +// +// addr.QuadPart = self.0 as _; +// +// addr +// } +// } +impl From for PHYSICAL_ADDRESS { + fn from(p: PhysicalAddress) -> Self { let mut addr: PHYSICAL_ADDRESS = unsafe { core::mem::zeroed() }; - addr.QuadPart = self.0 as _; + addr.QuadPart = p.0 as _; addr } @@ -57,11 +71,29 @@ pub enum CopyAddress { unsafe impl Send for CopyAddress {} unsafe impl Sync for CopyAddress {} -impl Into<(u32, MM_COPY_ADDRESS)> for CopyAddress { - fn into(self) -> (u32, MM_COPY_ADDRESS) { +// impl Into<(u32, MM_COPY_ADDRESS)> for CopyAddress { +// fn into(self) -> (u32, MM_COPY_ADDRESS) { +// let mut copy_addr: MM_COPY_ADDRESS = unsafe { core::mem::zeroed() }; +// +// let flags = match self { +// CopyAddress::Virtual(addr) => { +// copy_addr.__bindgen_anon_1.VirtualAddress = addr as _; +// MM_COPY_MEMORY_VIRTUAL +// } +// CopyAddress::Physical(addr) => { +// copy_addr.__bindgen_anon_1.PhysicalAddress = addr.into(); +// MM_COPY_MEMORY_PHYSICAL +// } +// }; +// +// (flags, copy_addr) +// } +// } +impl From for (u32, MM_COPY_ADDRESS) { + fn from(c: CopyAddress) -> Self { let mut copy_addr: MM_COPY_ADDRESS = unsafe { core::mem::zeroed() }; - let flags = match self { + let flags = match c { CopyAddress::Virtual(addr) => { copy_addr.__bindgen_anon_1.VirtualAddress = addr as _; MM_COPY_MEMORY_VIRTUAL -- cgit v1.2.3