pub trait MemoryAddr:
Copy
+ From<usize>
+ Into<usize>
+ Ord {
Show 23 methods
// Provided methods
fn align_down<U>(self, align: U) -> Self
where U: Into<usize> { ... }
fn align_up<U>(self, align: U) -> Self
where U: Into<usize> { ... }
fn align_offset<U>(self, align: U) -> usize
where U: Into<usize> { ... }
fn is_aligned<U>(self, align: U) -> bool
where U: Into<usize> { ... }
fn align_down_4k(self) -> Self { ... }
fn align_up_4k(self) -> Self { ... }
fn align_offset_4k(self) -> usize { ... }
fn is_aligned_4k(self) -> bool { ... }
fn offset(self, offset: isize) -> Self { ... }
fn wrapping_offset(self, offset: isize) -> Self { ... }
fn offset_from(self, base: Self) -> isize { ... }
fn add(self, rhs: usize) -> Self { ... }
fn wrapping_add(self, rhs: usize) -> Self { ... }
fn overflowing_add(self, rhs: usize) -> (Self, bool) { ... }
fn checked_add(self, rhs: usize) -> Option<Self> { ... }
fn sub(self, rhs: usize) -> Self { ... }
fn wrapping_sub(self, rhs: usize) -> Self { ... }
fn overflowing_sub(self, rhs: usize) -> (Self, bool) { ... }
fn checked_sub(self, rhs: usize) -> Option<Self> { ... }
fn sub_addr(self, rhs: Self) -> usize { ... }
fn wrapping_sub_addr(self, rhs: Self) -> usize { ... }
fn overflowing_sub_addr(self, rhs: Self) -> (usize, bool) { ... }
fn checked_sub_addr(self, rhs: Self) -> Option<usize> { ... }
}Expand description
A trait for memory address types.
Memory address types here include both physical and virtual addresses, as well as any other similar types like guest physical addresses in a hypervisor.
This trait is automatically implemented for any type that is Copy,
From<usize>, Into<usize>, and Ord, providing a set of utility methods
for address alignment and arithmetic.
Provided Methods§
Sourcefn align_down<U>(self, align: U) -> Self
fn align_down<U>(self, align: U) -> Self
Aligns the address downwards to the given alignment.
Sourcefn align_offset<U>(self, align: U) -> usize
fn align_offset<U>(self, align: U) -> usize
Returns the offset of the address within the given alignment.
Sourcefn is_aligned<U>(self, align: U) -> bool
fn is_aligned<U>(self, align: U) -> bool
Checks whether the address has the demanded alignment.
Sourcefn align_down_4k(self) -> Self
fn align_down_4k(self) -> Self
Aligns the address downwards to 4096 (bytes).
Sourcefn align_up_4k(self) -> Self
fn align_up_4k(self) -> Self
Aligns the address upwards to 4096 (bytes).
Sourcefn align_offset_4k(self) -> usize
fn align_offset_4k(self) -> usize
Returns the offset of the address within a 4K-sized page.
Sourcefn is_aligned_4k(self) -> bool
fn is_aligned_4k(self) -> bool
Checks whether the address is 4K-aligned.
Sourcefn wrapping_offset(self, offset: isize) -> Self
fn wrapping_offset(self, offset: isize) -> Self
Adds a given offset to the address to get a new address.
Unlike offset, this method always wraps around on overflow.
Sourcefn offset_from(self, base: Self) -> isize
fn offset_from(self, base: Self) -> isize
Gets the distance between two addresses.
§Panics
Panics if the result is not representable by isize.
Sourcefn add(self, rhs: usize) -> Self
fn add(self, rhs: usize) -> Self
Adds a given unsigned offset to the address to get a new address.
This method is similar to offset, but it takes an unsigned offset.
§Panics
Panics if the result overflows.
Sourcefn wrapping_add(self, rhs: usize) -> Self
fn wrapping_add(self, rhs: usize) -> Self
Adds a given unsigned offset to the address to get a new address.
Unlike add, this method always wraps around on overflow.
Sourcefn overflowing_add(self, rhs: usize) -> (Self, bool)
fn overflowing_add(self, rhs: usize) -> (Self, bool)
Adds a given unsigned offset to the address to get a new address.
Unlike add, this method returns a tuple of the new address and a boolean indicating
whether the addition has overflowed.
Sourcefn checked_add(self, rhs: usize) -> Option<Self>
fn checked_add(self, rhs: usize) -> Option<Self>
Adds a given unsigned offset to the address to get a new address.
Unlike add, this method returns None on overflow.
Sourcefn sub(self, rhs: usize) -> Self
fn sub(self, rhs: usize) -> Self
Subtracts a given unsigned offset from the address to get a new address.
This method is similar to offset(-rhs), but it takes an unsigned offset.
§Panics
Panics if the result overflows.
Sourcefn wrapping_sub(self, rhs: usize) -> Self
fn wrapping_sub(self, rhs: usize) -> Self
Subtracts a given unsigned offset from the address to get a new address.
Unlike sub, this method always wraps around on overflowed.
Sourcefn overflowing_sub(self, rhs: usize) -> (Self, bool)
fn overflowing_sub(self, rhs: usize) -> (Self, bool)
Subtracts a given unsigned offset from the address to get a new address.
Unlike sub, this method returns a tuple of the new address and a boolean indicating
whether the subtraction has overflowed.
Sourcefn checked_sub(self, rhs: usize) -> Option<Self>
fn checked_sub(self, rhs: usize) -> Option<Self>
Subtracts a given unsigned offset from the address to get a new address.
Unlike sub, this method returns None on overflow.
Sourcefn sub_addr(self, rhs: Self) -> usize
fn sub_addr(self, rhs: Self) -> usize
Subtracts another address from the address to get the offset between them.
§Panics
Panics if the result overflows.
Sourcefn wrapping_sub_addr(self, rhs: Self) -> usize
fn wrapping_sub_addr(self, rhs: Self) -> usize
Subtracts another address from the address to get the offset between them.
Unlike sub_addr, this method always wraps around on overflow.
Sourcefn overflowing_sub_addr(self, rhs: Self) -> (usize, bool)
fn overflowing_sub_addr(self, rhs: Self) -> (usize, bool)
Subtracts another address from the address to get the offset between them.
Unlike sub_addr, this method returns a tuple of the offset and a boolean indicating
whether the subtraction has overflowed.
Sourcefn checked_sub_addr(self, rhs: Self) -> Option<usize>
fn checked_sub_addr(self, rhs: Self) -> Option<usize>
Subtracts another address from the address to get the offset between them.
Unlike sub_addr, this method returns None on overflow.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".