#[repr(transparent)]pub struct Va(usize);Expand description
Represents a virtual address.
The Va (Virtual Address) struct represents an address in the virtual
memory space used by the kernel or user-space applications.
This abstraction provides utility methods for validation, alignment, and address manipulation, ensuring safe and consistent handling of virtual addresses.
Tuple Fields§
§0: usizeImplementations§
Source§impl Va
impl Va
Sourcepub const fn new(addr: usize) -> Option<Self>
pub const fn new(addr: usize) -> Option<Self>
Creates a new virtual address if the address is valid.
This method checks whether the given address falls within the valid
virtual address range. If it does, a Some(Va) is returned;
otherwise, None is returned.
§Arguments
addr: Ausizerepresenting the virtual address.
§Returns
Some(Va): If the address is within the valid virtual memory range.None: If the address is invalid.
§Example
let va = Va::new(0xFFFF_8000_1234_5678);
assert!(va.is_some()); // Valid virtual address
let invalid_va = Va::new(0xFFFF_7000_1234_5678);
assert!(invalid_va.is_none()); // Invalid virtual addressSourcepub const fn into_usize(self) -> usize
pub const fn into_usize(self) -> usize
Returns the raw usize representation of the virtual address.
This method allows extracting the underlying usize value, enabling
low-level operations or conversions between address types.
§Returns
- The virtual address as a
usize.
§Example
let va = Va::new(0xFFFF_8000_1234_5678).unwrap();
let raw_addr = va.into_usize();
assert_eq!(raw_addr, 0xFFFF_8000_1234_5678);Sourcepub const fn page_down(self) -> Self
pub const fn page_down(self) -> Self
Aligns the virtual address down to the nearest page boundary.
This method ensures that the address is aligned to the start of its memory page by clearing the lower bits that represent the page offset.
§Returns
- A new
Vainstance representing the aligned address.
§Example
let va = Va::new(0xFFFF_8000_1234_5678).unwrap();
let aligned = va.page_down();
assert_eq!(aligned.into_usize(), 0xFFFF_8000_1234_5000); // Example alignmentSourcepub const fn page_up(self) -> Self
pub const fn page_up(self) -> Self
Aligns the virtual address up to the nearest page boundary.
This method rounds up the address to the next memory page.
§Returns
- A new
Vainstance representing the aligned address.
§Example
let va = Va::new(0xFFFF_8000_1234_5678).unwrap();
let aligned = va.page_up();
assert_eq!(aligned.into_usize(), 0xFFFF_8000_1234_6000); // Example alignmentSourcepub const fn offset(self) -> usize
pub const fn offset(self) -> usize
Extracts the offset within the memory page from the virtual address.
This method retrieves the lower bits of the address that indicate the position within a page, which is useful for memory management and page-related operations.
§Returns
- The offset within the page as a
usize.
§Example
let va = Va::new(0xFFFF_8000_1234_5678).unwrap();
let offset = va.offset();
assert_eq!(offset, 0x678); // Example offset within the pageTrait Implementations§
Source§impl AddAssign<usize> for Va
impl AddAssign<usize> for Va
Source§fn add_assign(&mut self, other: usize)
fn add_assign(&mut self, other: usize)
+= operation. Read moreSource§impl BitAndAssign<usize> for Va
impl BitAndAssign<usize> for Va
Source§fn bitand_assign(&mut self, other: usize)
fn bitand_assign(&mut self, other: usize)
&= operation. Read moreSource§impl BitOrAssign<usize> for Va
impl BitOrAssign<usize> for Va
Source§fn bitor_assign(&mut self, other: usize)
fn bitor_assign(&mut self, other: usize)
|= operation. Read moreSource§impl Ord for Va
impl Ord for Va
Source§impl PartialOrd for Va
impl PartialOrd for Va
Source§impl SubAssign<usize> for Va
impl SubAssign<usize> for Va
Source§fn sub_assign(&mut self, other: usize)
fn sub_assign(&mut self, other: usize)
-= operation. Read moreimpl Copy for Va
impl Eq for Va
impl StructuralPartialEq for Va
Auto Trait Implementations§
impl Freeze for Va
impl RefUnwindSafe for Va
impl Send for Va
impl Sync for Va
impl Unpin for Va
impl UnwindSafe for Va
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)