From 1ce711c0611b8998b9a14089cf80ffc2553ff800 Mon Sep 17 00:00:00 2001 From: aarkegz Date: Wed, 21 Aug 2024 13:16:01 +0800 Subject: [PATCH] add two more functions to `VirtAddr` --- memory_addr/src/addr.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/memory_addr/src/addr.rs b/memory_addr/src/addr.rs index de9996f..30450c9 100644 --- a/memory_addr/src/addr.rs +++ b/memory_addr/src/addr.rs @@ -300,11 +300,23 @@ impl VirtAddr { self.0 as *const u8 } + /// Converts the virtual address to a raw pointer of a specific type. + #[inline] + pub const fn as_ptr_of(self) -> *const T { + self.0 as *const T + } + /// Converts the virtual address to a mutable raw pointer. #[inline] pub const fn as_mut_ptr(self) -> *mut u8 { self.0 as *mut u8 } + + /// Converts the virtual address to a mutable raw pointer of a specific type. + #[inline] + pub const fn as_mut_ptr_of(self) -> *mut T { + self.0 as *mut T + } } /// Alias for [`PhysAddr::from_usize`].