pub struct VAddr(/* private fields */);
Implementations§
Source§impl VAddr
impl VAddr
pub fn from_usize_checked(u: usize) -> Result<Self, InvalidAddress>
Sourcepub const unsafe fn from_usize_unchecked(u: usize) -> Self
pub const unsafe fn from_usize_unchecked(u: usize) -> Self
Constructs a VAddr
from an arbitrary usize
value without checking
if it’s valid.
Pros of this function:
- can be used in const-eval contexts
Cons of this function:
- “refer to ‘Safety’ section”
§Safety
u can use dis function to construct invalid addresses. probably dont do that.
Sourcepub fn from_ptr<T: ?Sized>(ptr: *const T) -> Self
pub fn from_ptr<T: ?Sized>(ptr: *const T) -> Self
Constructs a VAddr
from a *const T
pointer, exposing its provenance.
pub fn of<T: ?Sized>(pointee: &T) -> Self
Source§impl VAddr
impl VAddr
pub const fn zero() -> Self
Sourcepub fn from_u64(u: u64) -> Self
pub fn from_u64(u: u64) -> Self
§Panics
- If debug assertions are enabled and the address is not valid for the target architecture.
Sourcepub fn align_up<A: Into<usize>>(self, align: A) -> Self
pub fn align_up<A: Into<usize>>(self, align: A) -> Self
Aligns self
up to align
.
The specified alignment must be a power of two.
§Panics
- If
align
is not a power of two. - If debug assertions are enabled and the aligned address is not valid for the target architecture.
Sourcepub fn align_down<A: Into<usize>>(self, align: A) -> Self
pub fn align_down<A: Into<usize>>(self, align: A) -> Self
Aligns self
down to align
.
The specified alignment must be a power of two.
§Panics
- If
align
is not a power of two. - If debug assertions are enabled and the aligned address is not valid for the target architecture.
Sourcepub fn offset(self, offset: isize) -> Self
pub fn offset(self, offset: isize) -> Self
Offsets this address by offset
bytes.
If the specified offset would overflow, this function saturates instead.
Sourcepub fn difference(self, other: Self) -> isize
pub fn difference(self, other: Self) -> isize
Returns the difference between self
and other
.
Sourcepub fn is_aligned<A: Into<usize>>(self, align: A) -> bool
pub fn is_aligned<A: Into<usize>>(self, align: A) -> bool
Returns true
if self
is aligned on the specified alignment.
Sourcepub fn is_aligned_for<T>(self) -> bool
pub fn is_aligned_for<T>(self) -> bool
Returns true
if self
is aligned on the alignment of the specified
type.
Sourcepub fn as_ptr<T>(self) -> *const T
pub fn as_ptr<T>(self) -> *const T
Converts this address into a const pointer to a value of type T
.
§Panics
- If
self
is not aligned for aT
-typed value.
Sourcepub fn as_mut_ptr<T>(self) -> *mut T
pub fn as_mut_ptr<T>(self) -> *mut T
Converts this address into a mutable pointer to a value of type T
.
§Panics
- If
self
is not aligned for aT
-typed value.
Sourcepub fn as_non_null<T>(self) -> Option<NonNull<T>>
pub fn as_non_null<T>(self) -> Option<NonNull<T>>
Converts this address into a Option<NonNull<T>>
from a
VAddr
, returning None
if the address is null.
§Panics
- If
self
is not aligned for aT
-typed value.
Trait Implementations§
Source§impl Add<usize> for VAddr
impl Add<usize> for VAddr
Source§fn add(self, rhs: usize) -> Self
fn add(self, rhs: usize) -> Self
Offset self
up by rhs
.
§Notes
- The address will be offset by the minimum addressable unit
of the target architecture (i.e. probably bytes), not by
by units of a Rust type like
{*const T, *mut T}::add
. - Therefore, resulting address may have a different alignment from the input address.
§Panics
- If the resulting address is invalid.
Source§impl AddAssign<usize> for VAddr
impl AddAssign<usize> for VAddr
Source§fn add_assign(&mut self, rhs: usize)
fn add_assign(&mut self, rhs: usize)
+=
operation. Read moreSource§impl AddAssign for VAddr
impl AddAssign for VAddr
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl Address for VAddr
impl Address for VAddr
Source§fn from_usize(u: usize) -> Self
fn from_usize(u: usize) -> Self
§Panics
- If debug assertions are enabled and the address is not valid for the target architecture.
fn as_usize(self) -> usize
Source§fn align_up_for<T>(self) -> Self
fn align_up_for<T>(self) -> Self
Source§fn align_down_for<T>(self) -> Self
fn align_down_for<T>(self) -> Self
Source§fn difference(self, other: Self) -> isize
fn difference(self, other: Self) -> isize
self
and other
.Source§fn is_aligned_for<T>(self) -> bool
fn is_aligned_for<T>(self) -> bool
true
if self
is aligned on the alignment of the specified
type.Source§fn as_ptr<T>(self) -> *const T
fn as_ptr<T>(self) -> *const T
T
. Read moreSource§fn as_mut_ptr<T>(self) -> *mut T
fn as_mut_ptr<T>(self) -> *mut T
T
. Read moreSource§impl Ord for VAddr
impl Ord for VAddr
Source§impl PartialOrd for VAddr
impl PartialOrd for VAddr
Source§impl SubAssign<usize> for VAddr
impl SubAssign<usize> for VAddr
Source§fn sub_assign(&mut self, rhs: usize)
fn sub_assign(&mut self, rhs: usize)
-=
operation. Read moreSource§impl SubAssign for VAddr
impl SubAssign for VAddr
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read more